Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago
Edited by DeceptiveCaster 4 years ago

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

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 sheepposu 561 — 4y
0
Do a findFirstChild instead of WaitForChild to makes sure you don't delay the playeradded and it is more efficient sheepposu 561 — 4y
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. DeceptiveCaster 3761 — 4y

2 answers

Log in to vote
1
Answered by
SmartNode 383 Moderation Voter
4 years ago

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)
0
they all worked Fxding_cam 60 — 4y
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 SmartNode 383 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

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

Answer this question