I’m making group doors and they work if the player is the right rank in the group. But I also have a system where players can be guested. But when the player is guested the doors dont turn cancollide = false. How can I fix this function
Script is located in StarterPlayerScripts
local groupId = 8364327
local Folder = game.Workspace.Ship.GroupDoors
local Staff = 20
local Pinnacle = 10
local Emerald = 8
local Platinum = 6
function updateDoorCollisions(tier)
for _, part in pairs(Folder[tier]:GetChildren()) do
part.CanCollide = false
end
end
game.Players.PlayerAdded:Connect(function(player)
player.ChildAdded:Connect(function(child)
if child.Name == "Guested" and child.Value == true then
local tier = player.GuestFolder.GuestTier.Value
updateDoorCollisions(tier)
end
end)
end)
if Player:GetRankInGroup(groupId) >= Staff then
updateDoorCollisions("Staff")
end
if Player:GetRankInGroup(groupId) >= Pinnacle then
updateDoorCollisions("Pinnacle")
end
if Player:GetRankInGroup(groupId) >= Emerald then
updateDoorCollisions("Emerald")
end
if Player:GetRankInGroup(groupId) >= Platinum then
updateDoorCollisions("Platinum")
end
That’s because you haven’t setted up a function to set the collisions to true, I recommend doing this, when the player is guested set all the door parts’ can collide to true and then re-run the checks for the group again, so that a guested user can only access the doors he’s supposed to.
local groupId = 8364327
local Folder = game.Workspace.Ship.GroupDoors
local Staff = 20
local Pinnacle = 10
local Emerald = 8
local Platinum = 6
local function updateDoorCollisions(tier)
for _, part in pairs(Folder[tier]:GetChildren()) do
if part:IsA("Part") then
part.CanCollide = false
end
end
game.Players.PlayerAdded:Connect(function(Player)
if Player:GetRankInGroup(groupId) >= Staff then
updateDoorCollisions("Staff")
end
if Player:GetRankInGroup(groupId) >= Pinnacle then
updateDoorCollisions("Pinnacle")
end
if Player:GetRankInGroup(groupId) >= Emerald then
updateDoorCollisions("Emerald")
end
if Player:GetRankInGroup(groupId) >= Platinum then
updateDoorCollisions("Platinum")
end
Player.ChildAdded:Connect(function(child)
if child.Name == "Guested" and child.Value == true then
local tier = player.GuestFolder.GuestTier
updateDoorCollisions(tier.Value)
end
end)
end)