【发布时间】:2021-10-07 12:15:45
【问题描述】:
当我杀死一个 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)
【问题讨论】:
-
看起来保存到“Creator”对象的任何值都用于定位杀死NPC的玩家。您的任何工具或枪支是否会修改此值?另外,当您测试此代码时,“输出”窗口中是否有任何错误。
-
我对@987654323@ 一无所知,但
local Leaderstats = tag.Value:findFirstChild("leaderstats")不应该类似于local score = tag.Value:findFirstChild("Score"),因为它是您要更改的IntValue分数,而不是BoolValueleaderstats。跨度> -
@KenY-N,他们正在使用
Leaderstats.Score.Value将Score 编入索引