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

how can i fix the infinite yield warning? [Solved]

the output keeps on saying.. Infinite yield possible on 'ReplicatedStorage:WaitForChild("RightHand")'__ here is the script

local rp = game.ReplicatedStorage
local RightHand = rp:WaitForChild("RightHand")

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:connect(function(character)
		-- i need to add to this line
	end)
end)

i dont know what im doing wrong even though the players right hand has spawned

3 comments

0

Make sure you spelled it correctly and that it is in that exact path. If it was, you wouldn't be getting this warning

0

Do a findFirstChild instead of WaitForChild to makes sure you don't delay the playeradded and it is more efficient

0

WaitForChild() has a second parameter that takes a number. That number is the number of seconds it will wait for the child to exist. If the child doesn't exist while it's waiting said seconds, WaitForChild() will return nil. Otherwise, it returns the first child by the given name. It's basically a timeout option.

2 answers

✓ Accepted answer

You should use FindFirstChild instead.

Generally, the infinite yield warning just means that there is a chance that the :WaitForChild is going to wait forever. This might be because the wait has been running for longer than 5 seconds.

local rp = game:GetService(“ReplicatedStorage”)
local RightHand = rp:FindFirstChild("RightHand")

game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        -- i need to add to this line
    end)
end)

2 comments

0

they all worked

0

@BashCaster - the second parameter is the bad answer, nobody sets the parameter because you never know how long it’ll take for the child to load

Make Sure that the "right hand" is in the replicated storage

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