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?
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.
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