首页 > 解决方案 > 杀死NPC时如何得分

问题描述

当我杀死一个NPC时,我的分数应该会增加,但不会。

这是我的代码。它位于我的 NPC 模型下。

local Humanoid = script.Parent.Humanoid
function PwntX_X() 
    local tag = Humanoid:findFirstChild("creator") 
    if tag ~= nil then 
        if tag.Value ~= nil then 
            local Leaderstats = tag.Value:findFirstChild("leaderstats") 
            if Leaderstats ~= nil then 
                Leaderstats.Score.Value = Leaderstats.Score.Value + 250 --Change Money to the stat that is increased. 
                wait(0.1) 
                script:remove() 
            end 
        end 
    end 
end 
Humanoid.Died:connect(PwntX_X) 

这是我的排行榜代码

game.Players.PlayerAdded:Connect(function(plr)
    local stats = Instance.new("BoolValue",plr)
    stats.Name = "leaderstats"
    
    local score = Instance.new("IntValue", stats)
    score.Name = "Score"
    score.Value = 0
end)

标签: luaroblox

解决方案


不确定,但看起来像

score.Value = Leaderstats.Score.Value

推荐阅读