How to make [x] only happen when you're nearby?

so, i was reading the wiki article for contextactionservice, and, i noticed this…


is there a way where i can accomplish this? i want to prioritize this for a switch, so only when you’re close by, it’ll activate, etc.

i’m not asking for someone to do this for me, i’d rather have an example of how to accomplish this, if that’s possible. thank you!

In your action handler function, you can scan over all the doors in your game to determine one of them is close enough, and then perform the “open door” action on that closest door if there is one.

If that seems not performant enough in case someone is spamming the button, you could run a loop that keeps track of the closest door to the player and updates it every .5 seconds or so. Then you can refer to that cached door value in your handler.

1 Like

oh, makes sense. thank you!
(hahah, you were the person yesterday who also helped me out with this function. thanks again)

2 Likes