Basically I was making a door script and I need help. Here is the code.
local door = game.Workspace.Door local player = -- LocalPlayer Here local magnitude = (door.Position - player.Position).magnitude print(magnitude) if magnitude < 12 then script.Parent.Frame.Visible = true elseif magnitude > 12 then script.Parent.Frame.Visible = false end
What I want to know is how to find the position of localplayer and also how to make magnitude update every second so the GUI will be removed if magnitude is over 12
EDIT: I used a while true do loop and it worked.
Whiletruedo loop every second would make the server super laggy, especially if you have a large map with a lot of part. Try using while wait(20) do. This will not lag the server. Although the con is that there will be 20 second delay until the function runs again. I suggest you implement .Touched and .TouchEnded function on a basepart near the door to make this successful and without any lag, hopefully. If you need a ready script, comment to this answer and I’ll provide you with one.
I hope this helps.