Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

"attempt to index nil with clone" problem, how can i fix it? pls help.

this is my first time ever scripting and im making a story game on roblox. im making the lobby and everything is fine until the gui to exit the bus didnt pop up, i checked the output and it says "attempt to index nil with clone" heres a part of my script

script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
            for i,v in pairs(Seats) do
                if Seats.Occupant == nil then
                hit.Parent.Humanoid.JumpPower = 0
                hit.Parent.Humanoid.WalkSpeed = 0
                Gui:Clone().Parent = player.PlayerGui <----- (where the problem occurs)
                player.Character.HumanoidRootPart.CFrame = Seats[math.random(1,17)].CFrame 
                wait(10)
                player.PlayerGui.ExitGui:Destroy()  
             

2 comments

0

You didn't tell what the GUI is, so it is nil. nil means nothing

0

FORMAT YOUR CODE

2 answers

✓ Accepted answer

You would need to define GUI. I would recommend putting the GUI in ServerStorage and then defining this variable at the top of your code:

local GUI = game.ServerStorage.NAMEOFYOURGUI

2 comments

0

thank you!!!

0

No problem

You never set "Gui" as a variable so it is nil. Make sure you define it.

local original = game.ServerStorage.ExitGui -- change accordingly to where your Gui is and the name of it
local Gui= original:Clone()
Gui.Parent = player.PlayerGui

This discussion is preserved as it was. New answers, comments, and votes are closed.