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.
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!