Staff-Only door with Clickdetector

Im making a sliding door for a drive thru in my restaurant and i want it to be only clickable by Staffs. How to do this? I already have a script for it

local door = script.Parent
local door2 = script.Parent.Parent
local sound = script.Parent.Slide
local turn = false

function click()
	if turn == true then 
		turn = false
        sound:Play()
		door.Transparency = 1
		door2.Transparency = 1
	else 
		turn = true
        sound:Play()
		door.Transparency = 0
		door2.Transparency = 0.3
	end
end
script.Parent.ClickDetector.MouseClick:Connect(click)``

This depends on how the people are “staff”. Are they staff in-game in your own system? Are they in a team called staff? Are they ranked staff in a group? Through what will you figure out if the player is staff or not am I asking.

Oh sorry i didn’t mentioned that, they are ranked in a group

You could loop through a table for staffs before making the player open/ close the door. If it does not match any of the staffs name, return the function!

Edit: nvm

For the click script you would want to use PlayerWhoClicked which basically lets the script see who clicked. This should return the player which you can then use Player:IsInGroup to find if they are in the group or not. If true then open the door if not then return end so the door will do nothing.

Edit: here is the script rewritten.

local door = script.Parent
local door2 = script.Parent.Parent
local sound = script.Parent.Slide
local turn = false

function click(PlayerWhoClicked)
	if turn == true and PlayerWhoClicked:IsInGroup(YOUR GROUP ID HERE) then 
		turn = false
        sound:Play()
		door.Transparency = 1
		door2.Transparency = 1
	else 
		turn = true
        sound:Play()
		door.Transparency = 0
		door2.Transparency = 0.3
	end
end
script.Parent.ClickDetector.MouseClick:Connect(click)
1 Like

Thanks for the Solution Almonty!!!

You can do GetRankInGroup instead of just doing IsInGroup. Since they have a rank in the group.

IsInGroup will only see if the player is in the group, not what rank they are.

I am assuming you only want the staff to walk through the door when it is being opened aswell. So to secure that make sure it is a local script so only the door will open for the local player. Beware I haven’t tested this script.

local door = script.Parent
local door2 = script.Parent.Parent
local sound = script.Parent.Slide
local turn = false
local rank = 1 -- put this to a number from 0-255 I believe (this is the ID/priority if u can call it that of the rank)
local group = 1 -- this is the ID of the group

function click()
	if game.Players.LocalPlayer:IsInGroup(group) and game.Players.LocalPlayer:GetRankInGroup(group) >= rank then --check if the localplayer is in the group and if is the required rank (staff)
		if turn == true then 
			turn = false
			sound:Play()
			door.Transparency = 1
			door2.Transparency = 1
		else 
			turn = true
			sound:Play()
			door.Transparency = 0
			door2.Transparency = 0.3
			end
		else
	end
end
script.Parent.ClickDetector.MouseClick:Connect(click)
1 Like

This shouldn’t work correctly since it only checks if the player is in the group, and not if the player also has the desired rank (staff).

Oh this also might work aswell!

But I wouldnt recommend doing theese things in the client since client can be easily accessed by exploiters and they can open the door for themselves so easily and also for other players staff will look like they are walking through the wall so instead you should use collision groups to make team only doors and heres a devhub article that can help: Collision Filtering | Roblox Creator Documentation

1 Like

I see what you mean, but exploiters can change “CanCollide” to false on any part anyways, so I don’t see why this would be more vulnerable to do. Also to solve the “walking through the door” thing you could just fire a server remote that only changes the transparency of the door, and not the collision.

Its true but just using collision groups will make it less complicated

1 Like