PcoWSkbVqDnWTu_dm2ix

Restricted/Team Doors

Restricted/Team Doors

5 min

In some games, it’s desirable to have doors or forcefields that certain players can pass through but others cannot. For instance, many team combat games will spawn players of each team in a safe area that other teams can’t access (so they aren’t attacked the moment they join or spawn).

There are various ways to accomplish this, but this tutorial utilizes articles/Collision Filtering|collision filtering to create doors that only certain players can pass through.

Creating the Doors

For this simple example, the doors are basic block parts in the workspace named “BlueDoor” and “RedDoor.” Their material is enum/Material|Glass and their BasePart/Transparency|Transparency is set to 0.5.

Collision Groups

Since these doors exist in the game world at the start, we can set up their collision groups immediately. In ServerScriptService, create a Script and paste the following code into it:

Player Assignment

Now we need to add spawning players to an appropriate collision group. There are various ways to assign individual players to a group, including:

  • Assign players a “color” based on their articles/Player Spawns and Teams|team color.
  • Check if the player has earned a special articles/Badges Special Game Awards|badge or purchased a articles/Game Passes One Time Purchases|game pass which lets them access a restricted area.

For simplicity in this tutorial, we’ll just assign all incoming players to the “blue” team and give them access through the blue door, but not the red door.

Collision Groups

As with the doors, let’s first set up player collision groups by adding these lines to the script:

Character Parts

When adding players to collision groups, it’s critical to remember that all parts of their character must be allowed to pass through the door — head, torso, arms, legs, feet, etc. We can do this with a function that finds all BasePart objects, the base class of both Part|Parts and MeshPart|MeshParts which make up the player’s avatar:

With this function in place, we can detect the Players/PlayerAdded event which then listens for the Player/CharacterAdded|CharacterAdded event and runs our setCollisionGroup() function with the bluePlayers collision group.

Collision Filtering

To finish up, we just need to define the collision groups that don’t collide with each other — specifically, blue players should not collide with blue doors, and red players should not collide with red doors.

Tags:
  • team
  • restricted
  • vip
  • collision