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

How would i make it detect the Closest player?

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)

1 comment

0

Can't tell why you are using camera for this.

1 answer

✓ Accepted answer

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

1 comment

0

This worked for me, thanks. Don't know why i was using the Camera for this either.

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