【发布时间】:2015-06-16 16:53:31
【问题描述】:
以下脚本在 print("2") 和 print("3") 之间中断,因为它找不到变量“tag”。我该如何解决这个问题?
local Humanoid = script.Parent.Zombie -- Or Zombie Or Whatever
function PwntX_X()
print("1")
local tag = Humanoid:findFirstChild("creator")
print("2")
if tag ~= nil then
print("3")
if tag.Value ~= nil then
print("4")
local Leaderstats = tag.Value:findFirstChild("leaderstats")
print("5")
if Leaderstats ~= nil then
print("6")
Leaderstats.Cash.Value = Leaderstats.Cash.Value + 5
print("7")
wait(0.1)`enter code here`
script:remove()
end
end
end
end
Humanoid.Died:connect(PwntX_X)
我已经有一个 100% 有效的排行榜脚本。该脚本用于名为“ROBLOX”的游戏。谢谢!
【问题讨论】:
-
更多的 Lua 方法来检查 not nil 是:if not tag then ... end
-
好的,我会改的。
-
为了回答您的实际问题,函数 findFirstChild("creator") 返回 nil,因此您必须发布该函数的代码以获得帮助。
-
关于
not tagvstag ~= nil,nil和false是假的,只要你不需要区分它们,not tag更干净。