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

how do i fix attept to index nil with FindFirstChild?

So the code works for about 2 or 3 minutes then it breaks and the get the error attept to index nil with FindFirstChild

local function activate()
	for i,v in pairs(Players:GetChildren()) do
    	if v ~= game.Players.LocalPlayer then
			if game.Players.PlayerAdded or game.Players.CharacterAdded or v then
				if v.Character:FindFirstChild('ball') then --error occurs here
					
				end
			end
    	end
	end
end
while found == true do
	activate() --error occurs here
	wait()
end

3 comments

0

Is character a valid child of v ?

0

it loops throught the players character if it finds it. it will execute the code

0

This would normally occur if the script doesn't have enough time to find the set object into the character. The character loads in first and then the script, unless the ball isn't cloning in the character, like answered by Nifemiplayz, use a wait function. Try to use wait(1) instead of wait()

1 answer

Everytime you use a loop make sure there is a wait() at the end; this will ensure that the loop will not break and will work smoothly

2 comments

0

i did not fix sorry i will incdlue my whole script

0

the wait needs a time preferably. Attempt to index nil means it didnt find it.

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