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)