Help with group doors

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
1 Like

Does child.Value == true mean checking if player guest value is true? and Is Folder[tier] just a part

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.

I misunderstood, so the issue with this is that if the Guested value is not set to true before it’s parented to the player,

this check right after the value is added will be false, try removing this last condition or waiting a second before checking.

Yes its checking if the player is guested, and the folder[tier] checks another folder based on tier for the parts inside it using GetChildren

How about this code

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)

I cant sure it would be worked