Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to find position of local player?

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.

2 comments

0

local player = game.Players.LocalPlayer.Character.Torso

0

Do I use while true do for loop every second?

1 answer

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.