为什么这个脚本不起作用?

以下脚本在 print("2") 和 print("3") 之间断开,因为它找不到变量 "tag"。我该如何修复?

local Humanoid = script.Parent.Zombie -- 或者僵尸或其他
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)
                script:remove()
            end
        end
    end
end
Humanoid.Died:connect(PwntX_X)

我已经有了一个百分之百工作的排行榜脚本。这个脚本被用于一个叫做“ROBLOX”的游戏。谢谢!

点赞
用户4771095
用户4771095

首先,scriptinghelpers.org是针对Roblox的一项类似于stackoverflow的服务。下次我建议你去那里询问问题。现在开始正文:

-- 如果您有进一步的问题,我的Roblox用户名是'ZeroBits'(删除本行)

DEBUG = true -- 调试输出,以便在完成后禁用它。
local function print_D(t)
    if DEBUG == true then warn(t) end end
print_D("DEBUG MODE,完成后将调试值更改为False")

local Humanoid = script.Parent:FindFirstChild("Zombie") -- 这里我们将使用FindFirstChild()
--if not Humanoid then -- 如果要影响名为“Humanoid”的对象,则取消注释此语句
--    Humanoid = script.Parent:FindFirstChild("Humanoid")
--end
function HumanoidKilled() -- 将函数名称更改为稍微不那么糟心的名称。
    print_D("1") -- 使用Print_D()函数与这些打印语句进行切换。
    local tag = Humanoid:FindFirstChild("creator") -- 将FindFirstChild()中的第一个字母大写。
    print_D("2")
    if not tag then
        warn("未找到标签,请检查Humanoid和Weapon脚本") -- 如果打印此内容,要么没有标记,要么存在严重问题,请检查具有标记的人形对象,以确保您使用的武器实际上会生成标记。
    else -- 更改'if tag ~= nil then'为'if not tag then 'do stuff' else',以简化代码并尽早添加else语句。
        print_D("3")
        if tag.Value then -- 删除“~= nil”,因为它只是无用的杂质。
            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() -- 将remove()切换为Destroy(),remove()已不推荐使用。
            end
       end
    end
end
Humanoid.Died:connect(HumanoidKilled)

这修复了脚本中的所有问题,并使其更加高效。如果仍然存在问题,则可能在标签创建脚本中,标签未存储在人形对象中,或标签未命名为“creator”。

此外,我将打印语句切换为print_D函数,该函数使用warn()而不是print(),几乎没有区别,除了在控制台中,调试文本将变为黄色,而不是白色。

此脚本用于名为“ROBLOX”的游戏。谢谢!

它是用于Roblox上的游戏,而不是称为Roblox的游戏。您说的类似于说; 我为Source Engine制作了此mod,当您实际上为Half-Life 2制作了该mod。

2015-04-10 22:41:50