Having an issue with :RegisterCollisionGroup. Characters can still collide with other characters

I’m having problems with register collision group and setting the parts to that group. can’t get it to work properly… maybe i’m missing something. does anyone have any suggestions?

here’s the documentation i’ve gone over after trying the deprecated version… the new version is what’s in the code.
BasePart | Documentation - Roblox Creator Hub

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

local PlayersGroup = "Players"

PhysicsService:RegisterCollisionGroup(PlayersGroup)
PhysicsService:CollisionGroupSetCollidable(PlayersGroup, PlayersGroup, false)

local function characterAdded(character)
	for _, part in character:GetChildren() do
		if part:IsA("BasePart") then
			part.CollisionGroup = PlayersGroup
		end
	end
end

local function playerAdded(player)
	player.CharacterAdded:Connect(characterAdded)
end

local function init()
	for _, player in Players:GetPlayers() do
		task.spawn(playerAdded, player)
	end
	Players.PlayerAdded:Connect(playerAdded)
end
init()

run characterAdded in playerAdded, the characters could have been added before CharacterAdded was connected

also, listen for children being added to character and set their collision group

1 Like

Try this:

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

PhysicsService:RegisterCollisionGroup("Characters")
PhysicsService:CollisionGroupSetCollidable("Characters", "Characters", false)

local function onDescendantAdded(descendant)
	-- Set collision group for any part descendant
	if descendant:IsA("BasePart") then
		descendant.CollisionGroup = "Characters"
	end
end

local function onCharacterAdded(character)
	-- Process existing and new descendants for physics setup
	for _, descendant in pairs(character:GetDescendants()) do
		onDescendantAdded(descendant)
	end
	character.DescendantAdded:Connect(onDescendantAdded)
end

Players.PlayerAdded:Connect(function(player)
	-- Detect when the player's character is added
	player.CharacterAdded:Connect(onCharacterAdded)
end)
1 Like

it was because the parts did not exist yet

i used CharacterAppearanceLoaded() instead of CharacterAdded and that worked.

local function playerAdded(player)
	if player.Character then
		characterAppearanceLoaded(player.Character)
	end
	player.CharacterAppearanceLoaded:Connect(characterAppearanceLoaded)
end

That shouldn’t be the case since when i tested it with .CharacterAdded it worked perfectly

it was for me. i have been testing in 2 player test server. character appearance worked because regular character added the parts were not loaded in yet when the function ran.

can you share your script so I can see the reason for this

His solution and your solution both work. CharacterAppearanceLoaded just runs when all the character appearance loads (descendants and accessories etc)

2 Likes

This was the script I used that worked with .CharacterAdded:

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

PhysicsService:RegisterCollisionGroup("Characters")
PhysicsService:CollisionGroupSetCollidable("Characters", "Characters", false)

local function onDescendantAdded(descendant)
	-- Set collision group for any part descendant
	if descendant:IsA("BasePart") then
		descendant.CollisionGroup = "Characters"
	end
end

local function onCharacterAdded(character)
	-- Process existing and new descendants for physics setup
	for _, descendant in pairs(character:GetDescendants()) do
		onDescendantAdded(descendant)
	end
	character.DescendantAdded:Connect(onDescendantAdded)
end

Players.PlayerAdded:Connect(function(player)
	-- Detect when the player's character is added
	player.CharacterAdded:Connect(onCharacterAdded)
end)

1 Like

the original script is in the listing. the only thing i’ve changed is the player added function. from character added to character appearance loaded. then if character already exist just run the function. i could add a wait for humanoid in my character appearance loaded function also… just to plan for any edge cases.
btw, i didn’t want to do it your way because of the childadded would be more taxing. just doesn’t seem necessary fr.

1 Like

characterappearenceloaded is more taxing that characteradded since it includes and additional check, which is to see if all parts are loaded.

but you’re using descendantAdded which would run everytime a descendant ha been added right

to be fair, both ways may not cause any issues haha. idk.

descendantadded is doing the task of characterloaded in a more efficient way.

i think it’s whatever but can you exxplain

Also, if you’re using getchildren to put all parts in the collision group, There will be some parts left out, causing it to not be completely reliable. Here’s the roblox documentation which clearly explains how to use collision group to disable character collisions: Collision Filtering | Documentation - Roblox Creator Hub

wow i did not find this on the docs lol. but i do not see where certain parts would not be in the group because of using getChildren(). and i’m looking through my character right now… i only see parts that are a child of the character. none that are descendants.

Even though your character might not have descendants that are base parts it is best practice and highly recommended to use the the roblox code for disabling player collisions.