How to prevent a player from entering an unauthorized area?

I have areas on the map where one player can enter and another player can’t.
How can I prevent a certain player from entering this unauthorized area, using a script?

Something like this:
image

Looking better, I found a solution based on this answer:

Creating invisible parts surrounding the unauthorized area and triggering the event BasePart.Touched, it is possible to test which player touched this part and prevent him from advancing to in there.

https://developer.roblox.com/en-us/api-reference/function/WorldRoot/FindPartsInRegion3

Use this, check if any of the parts of a player’s character are in a given Region3 value, if they are then simply kill the character or teleport it somewhere outside of the Region3 area.

1 Like

Instead of killing or teleporting, how would I go about simply preventing the character from entering the area, as if he were “bumping” into a solid wall?

Perhaps a solution to allow one player to enter an area and another could not be:

  1. Create an invisible part surrounding the entire area
  2. Set this invisible part with CanCollide false and CanTouch true.
  3. Detect Touch from this part and if it is an unauthorized player, change CanCollide to true.

But in this case it wouldn’t work if both players (the authorized player and the unauthorized player) were in the same area, as CanCollide would be active for both players at the same time and would prevent both players from entering the area, not just the unauthorized player…

Any ideas?

Alright so don’t overthink it, all you need to do is to create “wall” as barrier to prevent people from entering and if I understood it correctly you want to make something like “pay to access” so you are going to need to use communication between server and client (I’d prefer RemoteFunction in this situation) player is going to ping server that they want to open the area’s “door” you are going to check if the player has enough currency and if does you are going to return success and you will remove the wall within the client. If you ask me - hey that’s easily exploitable well yeah but you can set up “Region” with OverlapParams and check with serverscript if player that hasn’t bought the area is inside and if is then you will simply revoke access and punish them (kick,teleport to spawn, kill etc.).

1 Like

I wouldn’t want to teleport or kill, I would just like to keep the player out, like when a player bumps into a wall.
Amazingly this is the hardest part…

Yes I get what do you aim for but you can’t really protect exploiter teleporting to the other area or destroying the barrier so you need to remove them from the area somehow that’s why I mentioned teleporting or killing.

1 Like