Restricted Doors

Restricted Doors

Mar 30 2021, 5:19 AM PST


You want to restrict access from a door and allow only specified players in.


Use CanCollide in conjunction with an exception table.

local allowed, door = {Player = true, Camoy = true}, Workspace.restrictedDoor
	if game.Players:FindFirstChild(hit.Parent.Name) and allowed[hit.Parent.Name] then
		door.CanCollide = false
		door.CanCollide = true


We first define our allowance array, then the door in which we want to use as our restricted access door. We connect the Touched event to the door and check to see if what hit the door is a player, and that they’re allowed inside.

We use a new BasePart/CanCollide|CanCollide property in order to set the ability of whether you can walk through the part or not. We then wait 1½ seconds and switch it back on. You want to make sure that the amount you wait is a low number. Say for example an allowed person enters the door and right behind them comes a not allowed person. They will be able to get through because the door has not become solid yet.

The reason we don’t need debounce here is because the action can be applied 20 times in a row and the door will act correctly. If we set BasePart/CanCollide|CanCollide to false twice, the first register will just make it true after its 1½ seconds is up, and the other will do the same only a little later.

  • vip
  • coding
  • gameplay
  • script
  • collision