distance = 10
game.Players.PlayerAdded:connect(function(p)
while wait() do
mag = (p.Character.Torso.Position - game.Workspace.Part.Position).magnitude
mag.Changed:connect(function()
mag = (p.Character.Torso.Position - game.Workspace.Part.Position).magnitude
if mag < distance then
p.PlayerGui.ScreenGui.atm.Visible = true
elseif mag > distance then
p.PlayerGui.ScreenGui.atm.Visible = false
end
end)
end
end)
this script is supposed to open up a gui when the player gets close enough to it. it works if i take out the .changed, but i dont want it lagging up the game. and another probem with the .Changed, whenever i run the script, it says in the output:
Workspace.mags:6: attempt to index global 'mag' (a number value)
i don't get this error. Is there anyway to do this with .Changed?

1 comment
I'm not 100% sure but I think it works fine without the changed.