:WaitForChild() Infinite Yield on Existing Instance

Hi all,

For some reason the script stops on an infinite yield despite the fact that the object actually exists.

CLIENT:

When I try to print it on the SERVER:
image

The server proves that the instance called exists, but for some reason the :WaitForChild() stays stuck in an infinite yield.

LOCAL SCRIPT:

local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local hrp = Character:WaitForChild("HumanoidRootPart")

local stand = Character:WaitForChild("Stand")
local StandRightArm = stand:WaitForChild("Stand Right Arm")

There is no misspellings or anything of that sort. What exactly is the issue here?

Thanks in advance.

1 Like
local StandRightArm = stand:WaitForChild("Stand Right Arm")

Try

local StandRightArm = stand:WaitForChild(["Stand Right Arm"])
1 Like

Could you show us the layout of the stand?

local StandRightArm = stand:FindFirstChild("Stand Right Arm") or stand:WaitForChild("Stand Right Arm")
1 Like

1 Like

Before the Right Arm there’s a :WaitForChild("Stand Head")
But somehow that one works just fine. So I don’t think the issue is related to the code syntax.

image

1 Like

Can you find out under what conditions this script is launched, is there a possible error in something else?

The issue happens when ping is high, otherwise it works fine.

I’ve never actually got to catch this error in studio testing, only in in-game testing

1 Like

you can add a condition that if it does not find it, it waits a few tenths of a second to repeat the same actions again

local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local hrp = Character:WaitForChild("HumanoidRootPart")

local stand = Character:WaitForChild("Stand")
local StandRightArm = stand:FindFirstChild("Stand Right Arm")

if StandRightArm == nil then
task.wait(0.3)
local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local hrp = Character:WaitForChild("HumanoidRootPart")

local stand = Character:WaitForChild("Stand")
local StandRightArm = stand:FindFirstChild("Stand Right Arm")
end

Stuff on the Server is already loaded while the Client needs to Download the Information, so it isn’t really a good comparison.

That’s why we use :WaitForChild() on the client, I don’t understand your point.

1 Like

It’s not gonna work, it’s gonna work for Spaced Letters Without :WaitForChild, :FindFirstChild, etc…

To use [], use it for Spaced Letters, like game.Players.LocalPlayer.PlayerGui["Random ScreenGui"]["Random Frame"]["Random TextButton"] Or for Dataload, to be like Currency_1.Value = Dataload[1]. Or for player on Workspace, use workspace[game.Players.LocalPlayer.Name] Which is the PlayerName. Like mine, if you use it, it’s going to be located as “kdopdaux1803”.

1 Like

Why not add a timeout?
local StandRightArm = stand:WaitForChild("Stand Right Arm" , 20)
The script will search for said instance for 20 seconds until it times out if it doesn’t find any.

1 Like

Because by default the timeout is math.huge (Edit: 5 seconds), so technically the localscript should eventually find that instance

1 Like

No it’s not?
Have you tried a custom timeout?
I have same issues on my game and adding a custom timeout usually fixed it.

Maybe I’m wrong about the default value (It’s actually 5 seconds) but nonetheless I have tried to set the timeout as math.huge and the error persisted

1 Like

Try without math.huge

1 Like

something may be deleting the right arm from the client. Try to monitore the Search All

That’s just a warning, feel free to ignore it. If you don’t want to see it use a pcall or add a timeout

Not how WaitForChild works, If the function never finds what it’s looking for, It completely halts the code. hence the "Infinite Yield" part of the warning
This is the WaitForChild description:
Returns the child of an Instance under the given name, If the child does not exist, it will yield the current thread until it does.

After that condition is never met, It halts the code.

WaitForChild has a Time out by Default, Time out Argument is just so you can change it manually instead of having 5 as the default