-1

以下脚本在 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”的游戏。谢谢!

4

1 回答 1

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”的游戏。谢谢!

是针对 Roblox 上的游戏,不是 Roblox 游戏,你说的就像是在说;我为 Source Engine 制作了这个模组,而你实际上为半条命 2 制作了模组

于 2015-04-10T22:41:50.343 回答