Attempt to index nil with 'WaitForChild'

So, the output says “Attempt to index nil with ‘WaitForChild’”


But Its Only Shows error inside roblox
In Roblox Studio it doesnt show any error and everything is working fine
i already googling and search in roblox devforum for hours and i didnt get any help for this

You might want to attach source code of your script to let us easily figure out your problem, thanks.

Please provide us the code, there’s no way we can help you without your code. Thanks

local loading
local chunkgenerated = 0
game.Players.PlayerAdded:Connect(function(player)
    loading = player.PlayerGui:WaitForChild("Loading")
end)

Inside a for loop
chunkgenerated=chunkgenerated+1 loading:WaitForChild("Chunk").Text = "("..chunkgenerated.."/289) Chunk Generated"
the error come from “:WaitForChild(“Chunk”)”

Try doing this:

local loading
local chunkgenerated = 0
game.Players.PlayerAdded:Connect(function(player)
    loading = player:WaitForChild("PlayerGui"):WaitForChild("Loading")
end)

Its says the same thing “Attempt to index nil with ‘WaitForChild’”

Can you show your explorer where the script is located?

its a script located in workspace

Try to put it in ServerScriptService or it could be some bug idk,but WaitForChild works fine

I assume you have placed for __ do loop out of the function that runs on PlayerAdded event.
You can fix it by placing loop inside function scope like below.

game.Players.PlayerAdded:Connect(function(player)
    local chunkgenerated = 0
    local loading
    loading = player.PlayerGui:WaitForChild("Loading")
    repeat
        chunkgenerated=chunkgenerated+1 loading:WaitForChild("Chunk").Text = ("chunkgenerated".."/289")
        wait()
    until chunkgenerated == 289
end)
1 Like

Thanks, the script is working right now