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

Infinite yield possible on workspace.LL0YD01:WaitForChild("HumanoidRootPart") ?

local plr = game.Players.LocalPlayer 
local char = plr.Character or plr.CharacterAdded:Wait()
local HumanoidAnchor = char:WaitForChild("HumanoidRootPart")
HumanoidAnchor.Anchored = true

What I am trying to achieve is when the Player joins the game the humanoid will be anchored but this message shows on the output: Infinite yield possible on workspace.LL0YD01:WaitForChild("HumanoidRootPart") How do I prevent this from happening?

2 comments

0

The warning “Infinite yield possible” actually means a thread can potentially yield infinitely. This usually arises when you use the :WaitForChild() function, as it just waits theoretically indefinitely for an instance to be added , and when over 5 seconds have elapsed without the function returning an Instance, it returns the error.

0

Ah, okay. Is this a good thing or a bad thing and how do I prevent this from happening?

2 answers

✓ Accepted answer

You need to change it to

players.Character:WaitForChild("HumanoidRootPart", 10).Anchored = true

The reason it says "Infininte Yield possible" is because you never defined a timeout value in case the HumanoidRootPart is not found. If for some reason the HumanoidRootPart was not there, it would cause the script to infinintely pause. If you add a number after the string, seperated by a comma, as seen in my example then it will automatically continue on with the rest of the script after that amount of seconds.

1 comment

0

Thank you so much!

It is because due to LL0YD01 being nil. In order to get the instance you have to make sure its parent is loaded. It means that the script is already loaded but the player isn't loaded yet. In order to fix this, you just add :WaitForChild() function.

for _, players in pairs(game.Players:GetPlayers()) do
    if players.Character:FindFirstChild("HumanoidRootPart") then
        players.Character:WaitForChild("HumanoidRootPart").Anchored = true
    end
end

6 comments

0

How would I make this possible for multiple players?

0

You can use for loop, I'll edit the script. and copy.

0

I copied it and I received a red underline saying Incomplete statement: expected assignment or a function call.

0

It's because of double '==' in .Anchored == true, make it only one '='

0

Ah, okay.

0

Still not anchored.

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