以下脚本在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”的游戏。谢谢!
答案 0 :(得分:0)
好吧,首先,scriptinghelpers.org是作为一种类似于专门针对Roblox的stackoverflow的服务而创建的,我建议下次,你问那里,现在开始的东西;
-- If you have further problems, My Roblox username is 'ZeroBits' (REMOVE THIS LINE)
DEBUG = true -- Debug Print, so you can disable it when you're done.
local function print_D(t)
if DEBUG == true then warn(t) end end
print_D("DEBUG MODE, Switch Debug Value to False when finished")
local Humanoid = script.Parent:FindFirstChild("Zombie") -- We'll use FindFirstChild() here
--if not Humanoid then -- Uncomment this statement if you want it to affect objects named Humanoid as well
-- Humanoid = script.Parent:FindFirstChild("Humanoid")
--end
function HumanoidKilled() -- Renamed the function to be a little less cringeworthy
print_D("1") -- switched these print statements with the Print_D() function
local tag = Humanoid:FindFirstChild("creator") -- Capitalized the first letter in FindFirstChild()
print_D("2")
if not tag then
warn("No Tag Found check Humanoid and weapon script") --if this prints, there's either no tag, or a serious problem, and you should check the humanoid object for a tag, or make sure the weapons you use actually generate tags.
else -- changed 'if tag ~= nil then' to 'if not tag then 'do stuff' else' to simplify the code, and add an else statement early on.
print_D("3")
if tag.Value then -- removed '~= nil' because it's just useless clutter
print_D("4")
local Leaderstats = tag.Value:findFirstChild("leaderstats")
print_D("5")
if Leaderstats ~= nil then
print_D("6")
Leaderstats.Cash.Value = Leaderstats.Cash.Value + 5
print_D("7")
wait(0.1)
script:Destroy() -- switched remove() to Destroy(), remove() is deprecated
end
end
end
end
Humanoid.Died:connect(HumanoidKilled)
这解决了脚本中的所有问题,并使其更有效。如果仍有问题,它可以在标签创建脚本中,标签不存储在人形机器人中,或者标签没有被命名为“创建者”。
另外,我将print语句切换到print_D函数,该函数使用warn()而不是print()几乎没有区别,除了调试文本在控制台中显示为黄色,而不是白色
脚本用于名为" ROBLOX"的游戏。谢谢!
对于一个游戏On Roblox,而不是一个名为Roblox的游戏,你所说的就像是在说;当你为Half-Life 2制作mod时,我为源引擎制作了这个mod