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

Magnitude not working, Error Infinite Yield, what does this mean?

So I am trying to learn Magnitude by doing a simple test

local frame = script.Parent.Frame
local part = game.Workspace.Test
local players = game:GetService("Players")
local player = players.LocalPlayer
local head = player:WaitForChild("Head")
wait()
if (part.Position - player.Character.head.Position).magnitude == 10 then
	frame.Visible = true
else
	frame.Visible = false
end

The goal is to be if the player is 10 studs away from the part a gui will appear. I get a prompt saying, "Infinite Yield Possible On Head" but what does this mean? And more importantly, what did I do wrong?

1 comment

1
  1. The player's Head is in their Character, not in the player itself. 2. Lua is case sensitive, so everything has to be spelt exactly how they are. 3. You have the player's head defined (although not from the Character), so why're you trying to get it from the player again?

1 answer

✓ Accepted answer

"Infinite Yeild Possible" shows when WaitForChild has been yeilding the code for a susiciously long time, you are searching the player object for the head, not the character in the workspace like you should be when searching for limbs, line 5 is:

local head = player:WaitForChild("Head")

line 5 should be:

local head = player.Character:WaitForChild("Head")

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