Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to find position of local player?

Asked by 7 years ago
Edited 7 years ago

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.

0
local player = game.Players.LocalPlayer.Character.Torso iipartyhat 25 — 7y
0
Do I use while true do for loop every second? The_sandwic 14 — 7y

1 answer

Log in to vote
0
Answered by
FazNook 61
7 years ago
Edited 7 years ago

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.

Ad

Answer this question