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

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

Asked by
LL0YD01 17
3 years ago
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?

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. ThatDevTim 188 — 3y
0
Ah, okay. Is this a good thing or a bad thing and how do I prevent this from happening? LL0YD01 17 — 3y

2 answers

Log in to vote
2
Answered by 3 years ago

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.

0
Thank you so much! LL0YD01 17 — 3y
Ad
Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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
0
How would I make this possible for multiple players? LL0YD01 17 — 3y
0
You can use for loop, I'll edit the script. and copy. Gabe_elvin1226aclan 323 — 3y
0
I copied it and I received a red underline saying Incomplete statement: expected assignment or a function call. LL0YD01 17 — 3y
0
It's because of double '==' in .Anchored == true, make it only one '=' Gabe_elvin1226aclan 323 — 3y
View all comments (2 more)
0
Ah, okay. LL0YD01 17 — 3y
0
Still not anchored. LL0YD01 17 — 3y

Answer this question