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

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

Asked by 5 years ago

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
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*? TheeDeathCaster 2368 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

"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")
Ad

Answer this question