local plr = game.Players.LocalPlayer
local rs = game:GetService("RunService")
local gui = script.Parent
local part = gui.Adornee or gui.Parent
local function calcDistance(a:BasePart,b:BasePart)
local pos1,pos2 = a.Position,b.Position
local dif = pos1-pos2
return dif.Magnitude
end
rs.RenderStepped:Connect(function()
local char = plr.Character
if char then
local ppart = char.PrimaryPart
if ppart then
local d = calcDistance(part,ppart)
if d > gui.MaxDistance then
gui.Enabled = false
else
gui.Enabled = true
end
end
end
end)
I found error: Localscripts in workspace doesn’t work, but serverscripts does!
Place my script in local enviroment like StarterGui or StarterCharacterScripts (StarterPlayerScripts). Don’t forgot for change gui path to needed. Use in this case workspace:WaitForChild(“NAME”) for get part because I got error (X is not child of workspace) while testing