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

How can i check if a part is within a certain distance in front of a player?

I'll break it down, I want to check if a player can see a part that is within ex:1 meter, how would i do this?

Any help is appreciated! thanks.

1 answer

✓ Accepted answer

By using magnitude: (LocalScript)

local mag = (part.Position - game.Players.LocalPlayer.Character.HumanoidRootPart.Position).magnitude

--Then you can use it like

if mag >= 5 then

	--Your code here

end

1 comment

0

In Roblox the measurements are studs, so this script will if the player is 5 studs away from the part. Note that this is a LocalScript, you mught need to use a RemoteEvent

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