Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Collision Admin Door Isn't Adding Players to Correct Collision Groups?

Asked by 3 years ago

I'm attempting to make an admin door for my game that uses collision groups. The collision groups I am working with are "Admin", which contains the parts of the door(s), "Admins", which I use to contain the parts of admin players that can go through the door, and "NotAdmins", for every player's parts of which are not admins.

My problem here is that I have it set up so, upon a player joining, they are checked for whether their name is on the admin list. Right away, all players are set to the "NotAdmins" collision group, but then their name is checked, and if it's on the list, they are set to the "Admins" list. However, with my script, it seems to be setting every player who joins in live game, whether their name is on the list or not, to the "Admins" list, and then setting every player, no matter their name, to "NotAdmins" in "Play" mode in Roblox Studio.

The script is a regular script in ServerScriptService. All of the player's parts are set to a collision group, and the door is always in the proper group, so I know those aren't the problem. There are also no errors in the actual code or in Output when running in "Play" mode, and Script Analysis does not report anything. All players in the game are Rthro with 1.0 body types.

Here's the part of my code that seems to be having the issue.

local function setCollisionGroup(character, groupName)
    for _, child in ipairs(character:GetChildren()) do
        if child:IsA("BasePart") then
            PhysicsService:SetPartCollisionGroup(child, groupName)
        end
    end
    character.DescendantAdded:Connect(function(descendant)
        if descendant:IsA("BasePart") then
            PhysicsService:SetPartCollisionGroup(descendant, groupName)
        end
    end)
end

--The above code is where the collideable parts of each player, upon joinng, are selected.

local AdminList = {"GreenFrosty17", "AmberEyeCanine"}

local Players = game:GetService("Players")

local function onPlayerAdded(player)

    local function onCharacterAdded(character)

        wait(3) --I had to add this so all collideable children of the player have enough time to be added.

        setCollisionGroup(character, NotAdmins)

        if player.Name == AdminList then

            setCollisionGroup(character, Admins)

        end

    end

    player.CharacterAdded:Connect(onCharacterAdded)

end

Players.PlayerAdded:Connect(onPlayerAdded)

--This is where the player is set either on the "Admins" or "NotAdmins" list. This seems to be the origin of the issue, but I included the first function just in case.

Answer this question