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

How to get info like how far the player is from an object a player clicked on?

Hello! I'd like to create a function inside a tool that when the player clicks mousebutton 1 it will check what object the player clicked on, and how far the player is from the object he clicked on. Like with a click detector, if you are within 5 studs and you click it, it runs a function. Kind of like that except you can only click with the tool selected. Thanks!

Note: Just tell me what APIs/Objects to use and if there is any equation to check how far the player is. Whether it be to calculate it from Vector3 or something else.

1 answer

First you would need a ClickDetector in a brick; and when you click it have a script fire from it. And in this function to find the distance between the player and the brick, use:

(brick.Position - player.HumanoidRootPart.Position).magnitude

Hope this helps!

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