0
votes

I am having an error with one of my scripts in Roblox Studio. The line that shows that is a problem is Line 13. The script is for basically to weld when somebody sits on the seat, and to start up the TankGUI (Another script that is fine).

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)

Please excuse any poor co-operation or language barriers I'm having. I'm still a bit new here.

1

1 Answers

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

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

Since you're declaring sitted as local, it goes out of scope at end, so it's gone when you try to use it in that if, so you're actually using a nil global variable there. Do this instead:

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

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

That way it'll stay in scope until you're actually done with it.