Select Users Only Door

How do I make a door that only allows them to move through if they have there name added to a script or a list? I’ve tried to look on youtube for a video but I haven’t found one…

This should work just watch and follow the steps. The word admin doesn’t automatically make them admins I believe It’s just a place holder name.

You would have to check whenever something touches the door if it’s parent(if the leg touched it then the parent is the player’s name)'s name is a children of the selected player list table
ex
local allowed = {“yourname”, “afriend’sname”}
local door = script.Parent
door.Touched:Connect(function(player)
for i, v inpairs(allowed) do
if player.Parent.Name == v then
door.CanCollide = true
wait(1)
door.CanCollide = false
end
end
end

This is what i threw together. This script runs on the server instead of on the client side.

For the script to work you have to make a collision group called Door

Also, keep in mind that this script is not optimized.

local PhysicsService = game:GetService("PhysicsService")
local PlayersAllowed = {"Player1"}
local Door = script.Parent

Door.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then else return end
	local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
		
	for i,v in pairs(PlayersAllowed) do
		if v == Player.Name then else return end
		
		local Character = Player.Character
		if Character then else end
		
		spawn(function()
			for i,v in pairs(Character:GetChildren()) do
				if v:IsA("BasePart") then
					PhysicsService:SetPartCollisionGroup(v,"Door")	
				end
			end
			
			wait(2)
			
			for i,v in pairs(Character:GetChildren()) do
				if v:IsA("BasePart") then
					PhysicsService:SetPartCollisionGroup(v, "Default")	
				end
			end	
		end)
		
		
	end
end)
2 Likes

Make an invisible wall and add a check so it’s deleted if the user is the user you want it to let enter.

Pretty simple, make a table put all the names in it, then when the door is touched, loop through the table and check if the player is in the table

WhiteList = {"yourname","friendsname"}

script.Parent.Touched:Connect(function(hit)
local hum = hit.Parent:FindFirstChild("Humanoid")
if hum then
      for i,v in pairs (WhiteList) do
           if v == hum.Parent.Name then 
           script.Parent.Transparency = 1
            script.Parent.CanCollide = false
             break
                   end
                end
            end)

Should work, haven’t fully tested it.

None of these seem to be working for me…

You’re on the right track, but you only need to set the collisions for the door once, not on touched. It should look more like this:

local PhysicsService = game:GetService("PhysicsService")
local DoorCollisionGroupName = "VIP_Door"
local PlayersAllowedInCollisionGroupName = "VIP_Door_Access"
local PlayersAllowed = {"Player1"} -- Case Sensitive!
local Door = script.Parent
PhysicsService:CreateCollisionGroup(DoorCollisionGroupName)
PhysicsService:CreateCollisionGroup(PlayersAllowedInCollisionGroupName)

PhysicsService:CollisionGroupSetCollidable(DoorCollisionGroupName, PlayersAllowedInCollisionGroupName, false) -- Make it so VIP_Door_Access can NOT collide with VIP_Door!
PhysicsService:CollisionGroupSetCollidable(DoorCollisionGroupName, "Default", true) -- Make it so Default (non-access players) CAN collide with VIP_Door!

-- Give players the collision group to enter, if they have permission:
game.Players.PlayerAdded:connect(function(Player)
	local function OnCharAdded(Character)
		if table.find(PlayersAllowed, Player.Name) then -- They are allowed in!
			for _, v in pairs(Character:GetChildren()) do
				if v:IsA("BasePart") then
					PhysicsService:SetPartCollisionGroup(v, PlayersAllowedInCollisionGroupName) -- Set the Character's body parts to the allowed in collision group!
				end
			end
		end
	end
	
	Player.CharacterAdded:connect(OnCharAdded)
	if Player.Character then -- did the character spawn before we set our event?
		OnCharAdded(Player.Character)
	end
end)

-- Now, give the door the same "VIP_Door" CollisionGroup:
PhysicsService:SetPartCollisionGroup(Door, DoorCollisionGroupName) -- Set the CollisionGroup of the door!

That’s it! This will work fine. Place this in a server script, not a local one.

5 Likes

All of these solutions (every solution except for @GRADE_1000’s) is NOT the proper way to do this! This will allow any players NEAR the allowed player to get in too! The entire door would unlock for EVERYONE for a brief period.

You don’t even need .Touched for this, my example code provided will work just fine, and will never let anyone who shouldn’t get through in.

2 Likes

Please note, I did edit my script, before it looped through descendants of the door (thought the door was a model), now it’s adjusted to only work for the part named “Door” aka script.Parent in this case.

Please try the updated version, it should work just fine for you. Let me know if you have any issues.