Cant figure out how to disable collisions for certain game objects!

local Players = game.Players
local PhysicsService = game:GetService("PhysicsService")

Players.PlayerAdded:Connect(function(Player)
    Player.CharacterAdded:Connect(function()
        for Index, Parts in ipairs(Player.Character:GetChildren()) do
            if Parts:IsA("BasePart") or Parts:IsA("Part") then
                PhysicsService:SetPartCollisionGroup(Parts, "Player")
                PhysicsService:RemoveCollisionGroup(0)
                PhysicsService:CollisionGroupSetCollidable("Player", "Bloons", false)
            end
        end
    end)
end)

PhysicsService:CollisionGroupSetCollidable("Player", "Bloons", false)
PhysicsService:CollisionGroupSetCollidable("Player", "Player", false)
PhysicsService:CollisionGroupSetCollidable("Player", "Default", true)

When the player is added just to the player collision group everything works fine, but roblox for some reason puts the player in 2 collision groups the default and the one I put the player in. Is there any way to stop this so it can work correctly?

Also make use of Character:DescendantAdded() because sometimes not everying loads in therefor sometimes it doesn’t get assigned a collision group:

Character.DescendantAdded:Connect(function(Object)
    if Object:IsA("BasePart") then
        PhysicsService:SetPartCollisionGroup(Parts, "Player")
    end
end)

And what is this line for?:

PhysicsService:RemoveCollisionGroup(0)

A Part is a base part so you don’t really need that extra check.


This line isn’t needded in the CharacterAdded function;

PhysicsService:CollisionGroupSetCollidable("Player", "Bloons", false)

These lines should be at the start of the code, right before the PlayerAdded function:

PhysicsService:CollisionGroupSetCollidable("Player", "Bloons", false)
PhysicsService:CollisionGroupSetCollidable("Player", "Player", false)
PhysicsService:CollisionGroupSetCollidable("Player", "Default", true)
1 Like

Thank you, this fixed the problem

1 Like