Check if player is near a Door

Hello Community,

I am currently working on a Project, right now working on the Doors and I do question myself whats the best memory efficient way to detect if a player is near a door.

Back then, I always looped through all doors and checked how far the player is away but thats prob. very inefficient.

Do you have any ideas which Methode is the best?

Its for the Interaction prompt, so that if you are near a door, you get a UI shown for example.

If you’re using the ProximityPrompt that Roblox provides they should appear automatically when you get close enough, at a distance you can configure. If you’re making your own prompts then you may have to manually check the distance to the player. Another possibility could be to use an invisible hitbox around the door and listen for a Touched event.

Yeah, I have also thought of using Zone+ to create Zones around it, but I am not sure if it is very healthy to create around 50 of them.

You can add an extended part and then do:
game.workspace:GetPartsInPart(doorExtenderPart)
Then loop through the parts it returned, check if it’s an ancestor of the player, if so, show proximity prompt. But proximity prompts do have a field, where you can specify the value at which the proximity prompt will be shown.

Make a part surrounding the door defining where you want the “region” to be.
Then use Region3 to see if the player is in the region of the part.