Hi, i wanted to make a while loop with this condition:
while (player remains in “MaxDistance” of the BillboardGUI) do
This Cause i have a lot of the same Instance and the performance will drop
Thanks
You can probably do this:
local Camera = workspace.CurrentCamera -- Players Camera
local Distance = (Camera.CFrame.Position - UI.Adorrne.Position).Magnitude -- Length
-- Distance by Camera for the BillboardGui
if Distance <= UI.MaxDistance then -- if statement
-- code
end
if Adorrne
is nil
, try doing UI.Parent
However, I may be unaware of an Event that does this, so ill look into it to see if there is.
My Script:
local HealthFrame = script.Parent
local HeathValue = script.Parent.Parent.Parent.Parent.Health
local Camera = workspace.CurrentCamera -- Players Camera
local Distance = (Camera.CFrame.Position - HealthFrame.Parent.Adorrne.Position).Magnitude -- Length
-- SETTINGS
local MaxValue = 50 -- Max healt Value Value
local MaxSize = 200 -- Max Frame Size
-- SETTINGS
while Distance <= HealthFrame.Parent.MaxDistance do
wait(2)
print("helo")
end
Locations:
Not printing any, not even saying Adorrne
is nil
LocalScripts
cannot run inside the workspace, if you want that to happen, try using a Server Script, and change its RunContext
Property to Client
.
Also, Its best that you Update the Length so its the recent one, to determine if they had stayed within that distance.
wait()
is deprecated, use task.wait()
I Placed a ServerScript
and changed RunContext
to Client
cause i need it to run in the client, now Gives me this error:
Adorrne is not a valid member of BillboardGui "Workspace.Terrain.0,-96.Coal.Stone.BGUI.Health"
if i use UI.Parent it refers to a Part
Thats because I misspelled it, its Adornee
, not Adorrne
local HealthFrame = script.Parent
local HeathValue = script.Parent.Parent.Parent.Parent.Health
local Camera = workspace.CurrentCamera -- Players Camera
local Distance = (Camera.CFrame.Position - HealthFrame.Parent.Adornee.Position).Magnitude -- Length
-- SETTINGS
local MaxValue = 50 -- Max healt Value Value
local MaxSize = 200 -- Max Frame Size
-- SETTINGS
while Distance <= HealthFrame.Parent.MaxDistance do
task.wait()
print("helo")
end
Error at line 4 attempt to index nil with 'Position'
then its because Adornee
is nil
, so try doing, HealthFrame.Parent.Parent
HealthFrame is the Frame, child of the BillboardGUI, if i write HealthFrame.Parent.Parent i refer to a part.
Adornee is not a valid member of Part "Workspace.Terrain.0,-96.Coal.Stone.BGUI
(“BGUI” is the Part)
Bruh, HealthFrame.Parent.Parent.Position
Now it’s not giving errors but not printing any