Roblox Studio error: Workspace.Driver.OnSeated!:13: attempt to index nil with ''Name''

Roblox Studio error: Workspace.Driver.OnSeated!:13: attempt to index nil with ''Name''

我在 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)

请原谅我遇到的合作不畅或语言障碍。我在这里还是有点陌生​​。

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

            if (sitted.Name ~= script.Parent.Owner.Value) then

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

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

            if (sitted.Name ~= script.Parent.Owner.Value) then

这样它就会一直在范围内,直到您真正完成它。