What's the best way to make smth like ProximityPrompt?

Hello. Today I got one question, which important for me.
Everyone (almost) know what ProximityPrompt is. It’s grey box which asks you hold/click mouse or press keybind.
Also, it becomes “active” when player is near it.


My question is:
What’s the best way to detect when player is near object?

  1. Constantly counting magnitude may work well, but not when there’s tons of them.
  2. Creating part which will detect when you reach radius. But have size limit of 2048 → radius of 1024 (IK that this’s more than enough xd) and will use function connection. With dozens of objects this won’t work well too.

So, does anyone have better ideas to detect when object is near another object than this?

Just use BillboardGui? You can set the max distance, and it automatically scales up and down when using offset.

1 Like

ProximityPrompt was just for example, we may need make similar thing on Parts. They haven’t that properties.

They do… I don’t understand. Simply set the max distance to your desired number. It will become invisible when you’re too far away. You don’t have to make a new proximity prompt unless you want to create a specific style for your game.

Guy, I want idea on how to make system which can do similar things like hiding/showing ProximityPrompts, not only on GUI objects, but on Parts too (for example).

One thing you can do is use the ProximityPrompt object with a Custom style, but don’t actually provide any UI for it to use. It will be invisible and then you’ll be able to hook into the PromptShown and PromptHidden events to show/hide your part or whatever it is you’re trying to do.

That said, there are many ways to do what you’re asking for. If the proposed solution here isn’t desirable we could potentially talk about some alternatives. But this one is VERY simple and easy to implement. You’ll have all of the same functionality as a ProximityPrompt without the UI.

2 Likes

As @CompilerError said there are many ways.

I can suggest for static proximity prompts to use Octrees, Otherwise I recommend looking through the tips for optimizing distance checks with octrees:

The main performance cost of doing this comes down to tracking and upating the position of the objects, which is fine if: 1) You have a way to detect the movement without having to loop through all the moving objects to update the position 2) You can tolerate some inaccuracy with positions and smear this update 3) You have less than 1000 objects to track, in this case looping through everything shouldn’t be too costly.

I don’t see why counting magnitude wouldn’t work well when there’s ton of them. I think that’s a perfect idea, you can connect it to a 0.2 second loop or something and it will work great

There’s no reason to count magnitude, when there’s already a property for that. BillboardGuis automatically have a property that is the max distance your camera has to be from it to be visible.

Did you read our conversations above? ProximityPrompt was just not very successfull example of what I trying to achieve.