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

How would i make it detect the Closest player?

Asked by
oSyM8V3N 429 Moderation Voter
6 years ago

Any help will be appreciated :)

local camera = game.Workspace.CurrentCamera
local part = workspace.SomePart --Locate your part here
local studsAway = 18 --set how many studs you the player needs to be in range of
game:GetService("RunService").RenderStepped:connect(function()
    if (camera.CoordinateFrame.p - part.Position).magnitude < studsAway then 
--Part is the part in workspace, and it works fine with it. I just need help making it detect the Closest player within 10 studs
print("hey")
    end
end)
0
Can't tell why you are using camera for this. Griffi0n 315 — 6y

1 answer

Log in to vote
0
Answered by
Griffi0n 315 Moderation Voter
6 years ago

What I would do

local player = game.Players.LocalPlayer
local part = game.Workspace.SomePart
local studsaway = 18

while true do
    if (player.Character.HumanoidRootPart.Position - part.Position).magnitude < studsaway then
        print("hey")
    end
    wait()
end
0
This worked for me, thanks. Don't know why i was using the Camera for this either. oSyM8V3N 429 — 6y
Ad

Answer this question