Group Rank Door Dual Entry Issue

Hello! I am currently working on a restaurant roleplay game, and I want areas such as kitchen, bar, staff rooms, etc to only be accessible to players with certain ranks in my group. The current script works, however, if a staff and a customer were to walk in at the same time the customer would also be able to access the rooms. I’ve tried to find similar topics on the forum and even hired a scripter to help me however it did not seem to work. Help would be appreciated, thanks!

Script:

local model = script.Parent
local door_1 = model.Door1
local detector_part = model.Detector

local players = game:GetService("Players")
local group_id = 34215674 
local rank_num = 255 
local is_open = false

local function door_function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local player = players:GetPlayerFromCharacter(hit.Parent)
		pcall(function()
			print(player.Name)
			if player then
				if player:GetRankInGroup(group_id) == rank_num then
					if is_open then return end
					--door_1["tada.wav/victory.wav HD"]:Play() 
					is_open = true
					door_1.CanCollide = false
					task.wait(1.5)
					--door_1["Access Denied"]:Play() 
					is_open = false
					door_1.CanCollide = true
				else
					door_1.CanCollide = true
				end
			end
		end)
	end
end

detector_part.Touched:Connect(function(hit)
	door_function(hit)
end)

I would recommend using Collision Groups. These should let you control specific characters having access, so that only designated players can walk through these doors.

1 Like

As stated, collision groups are a good option or you can modify collision properties locally.

1 Like

so this should work
script -
local model = script.Parent
local door_1: Part = model.Door1
local detector_part = model.Detector

local players = game:GetService(“Players”)
local group_id = 34215674
local rank_num = 255
local is_open = false

local function GetPlrRank(plr: Player)
local Rank = plr:GetRankInGroup(group_id)
return Rank
end

local function door_function(hit: Instance)
if hit.Parent:FindFirstChild(“Humanoid”) then
local plr = players:GetPlayerFromCharacter(hit.Parent)
local PlrRank = GetPlrRank(plr)
if is_open == true then
return
end
if PlrRank == 255 then
is_open = true
door_1.CanCollide = false
door_1.Transparency = 1
task.wait(.5)
door_1.CanCollide = true
door_1.Transparency = 0
is_open = false
end
end
end

detector_part.Touched:Connect(door_function)

video while in top group

video while not in group


so yeah

Thanks, edited the script and the script works now!

1 Like