Skinstashery
Roblox
Home / Roblox / Studio script library / Team-only door
RB-004

Roblox team-only door script

A door that only opens for players on one team.

Script type
Script
Where it goes
Inside the door Part
Category
Doors and interaction

For your own game in Roblox Studio. Not for use in other people's games.

The code

-- Team-only door: opens briefly when a member of the right team touches it.

local TEAM_NAME = "Red"     -- the exact name of the team in the Teams service
local OPEN_TIME = 2          -- seconds the door stays open

local Players = game:GetService("Players")

local door = script.Parent
local isOpen = false

door.Touched:Connect(function(hit)
	if isOpen then
		return
	end

	local player = Players:GetPlayerFromCharacter(hit.Parent)
	if not player or not player.Team then
		return
	end
	if player.Team.Name ~= TEAM_NAME then
		return
	end

	isOpen = true
	door.CanCollide = false
	door.Transparency = 0.7

	task.wait(OPEN_TIME)

	door.CanCollide = true
	door.Transparency = 0
	isOpen = false
end)

How to set it up

  1. In the Explorer, find Teams. Click the plus button and add a Team. Name it Red and pick a TeamColor.
  2. Add a second Team (for example Blue). Add a SpawnLocation for each team and set its TeamColor and Neutral = false.
  3. Insert a Part for the door, set Anchored to true, and add a Script to it with the code.
  4. Play. Players on Red can walk through. Players on Blue cannot.

Change it

More in Doors and interaction

All Roblox scripts

More Roblox tools