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

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

Asked by 6 years ago
Edited 6 years ago

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

Log in to vote
0
Answered by 6 years ago

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!

Ad

Answer this question