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

How to stop infinite yield/nil value?

I'm creating a simple coordinates gui but this one error keeps stopping it from working for most people. The script is:

plr = game.Players.LocalPlayer
char = plr:WaitForChild("Character")
while true do
	script.Parent.Text = tostring(math.ceil(char.Torso.Position.x)..", "..math.ceil(char.Torso.Position.y)..", "..math.ceil(char.Torso.Position.z))
	wait(0.1)
end

And I get the error that there is an "infinite yield" for the char variable, but before I made it WaitForChild it said that char was a "nil value." How do I make this work?

1 answer

✓ Accepted answer

The character isn't a child of the player, it's a property.

Sometimes there won't be a character, and to wait for it you do this:

local char = plr.Character or plr.CharacterAdded:Wait()

Also use local variables.

2 comments

1

Thanks :)

1

Oh wow this will be really useful :)

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