【问题标题】:Roblox Studio error: Workspace.Driver.OnSeated!:13: attempt to index nil with ''Name''Roblox Studio 错误:Workspace.Driver.OnSeated!:13:尝试使用“名称”索引 nil
【发布时间】:2020-08-16 01:52:15
【问题描述】:

我在 Roblox Studio 中的一个脚本出现错误。显示有问题的行是第 13 行。该脚本基本上用于在有人坐在座位上时进行焊接,并启动 TankGUI(另一个很好的脚本)。

seat = script.Parent

function onChildAdded(part)
    if (part.className == "Weld") then
        while true do
local           welde = seat:FindFirstChild("SeatWeld")

            if (welde ~= nil) then
local           sitted = welde.Part1.Parent
            end

            if (sitted.Name ~= script.Parent.Owner.Value) then
                if (script.Parent.Owner.Value == "NoOne") then
                    script.Parent.Owner.Value = sitted.Name
                    print ("sitted steal")
                else
                    print ("stolen!!")
local                   shipstealer = game.Workspace:FindFirstChild(sitted.Name)
                    if (shipstealer ~= nil) then
                        shipstealer.Humanoid.Jump=true
                    end
                end
            end


            wait(0.2)

            if (welde == nil) then
                print("BreakLoop")
                script.Parent.Owner.Value = "NoOne"
            break end
        end
    end
end

--while true do
--  wait(0.5)
--  script.Parent.Parent.Name=script.Parent.Owner.Value .. "'s Ship"
--end
seat.ChildAdded:connect(onChildAdded)

请原谅我遇到的任何合作不善或语言障碍。我这里还是有点新意。

【问题讨论】:

    标签: lua roblox


    【解决方案1】:
                if (welde ~= nil) then
    local           sitted = welde.Part1.Parent
                end
    
                if (sitted.Name ~= script.Parent.Owner.Value) then
    

    由于您将sitted 声明为local,因此它超出了end 的范围,因此当您尝试在该if 中使用它时它就消失了,因此您实际上使用的是零全局那里的变量。改为这样做:

                local sitted
                if (welde ~= nil) then
                    sitted = welde.Part1.Parent
                end
    
                if (sitted.Name ~= script.Parent.Owner.Value) then
    

    这样它会一直保持在范围内,直到您真正完成它为止。

    【讨论】:

    • 呃,我遇到了另一个问题。 Workspace.Model.Turret.Driver.OnSeated!:48: 预期的“结束”(在第 4 行关闭“功能”),得到
    • @qaquahasam 听起来你不小心用这个修复破坏了一些东西。仔细检查您是否不小心添加了额外的function 或删除了end
    • 大声笑,改变了一件事,两个不同的脚本坏了。我现在修复了脚本。如果我需要更多帮助,我会发布一个问题。非常感谢您的帮助!
    猜你喜欢
    • 2020-08-17
    • 2021-09-30
    • 1970-01-01
    • 2022-01-10
    • 2020-11-22
    • 2021-09-23
    • 2020-12-16
    • 2022-11-23
    • 2021-10-10
    相关资源
    最近更新 更多