Ad
Log in to vote
0

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

Asked by 10 months ago
Edited by Leamir 10 months ago

Please encode Lua code in the Lua block code tag (look for the Lua icon in the editor).

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()  

0
You didn't tell what the GUI is, so it is nil. nil means nothing Shounak123 379 — 10mo
0
FORMAT YOUR CODE rabbi99 617 — 10mo

2 answers

Log in to vote
0
Answered by 10 months ago

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
0
thank you!!! Nightsblox19 2 — 10mo
0
No problem CreationNation1 459 — 10mo
Ad
Log in to vote
0
Answered by 10 months ago

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

Answer this question