Hi, I have a group rank door that only lets people in my group in but occasionally it lets people that aren’t the high enough role in the group in? Should I put a PlayerAdded event in a local script and set the doors cancollide to false if they’re in the group?
code:
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local player = game.Players:FindFirstChild(hit.Parent.Name)
if player:GetRankInGroup(7886882) >= 3 then
script.Parent.CanCollide = false
else
script.Parent.CanCollide = true
end
end
end)
local System = {
Running = false,
Functions = {},
GroupId = 7886882,
MinRank = 3,
MaxRank = 255,
Cooldown = 0.5
}
function System.Functions.CloseDoor(door)
door.CanCollide = true
System.Running = false
end
function System.Functions.OpenDoor(door)
door.CanCollide = false
wait(System.Cooldown or 2)
System.Functions.CloseDoor(door)
end
function System.Functions.Run(hit)
local GID,Min,Max = System.GroupId,System.MinRank,System.MaxRank
local Players = game:GetService("Players")
local player = Players:GetPlayerFromCharacter(hit.Parent)
if not player or not GID or not Min or not Max then
System.Running = false
return
end
local rank = player:GetRankInGroup(GID)
if rank >= Min and rank <= Max then
System.Functions.OpenDoor(script.Parent)
end
end
script.Parent.Touched:Connect(function(hit)
if System.Running == false then
System.Running = true
System.Functions.Run(hit)
else
return
end
end)
If you really want to do this the exact way you scripted it, I would suggest using FireClient() and set the CanCollide property there.
Doing this on the server-side will let everyone in as that change is automatically replicated to all players.
However, FireClient will solve that issue.