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?
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()
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)
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
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.
His solution and your solution both work. CharacterAppearanceLoaded just runs when all the character appearance loads (descendants and accessories etc)
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)
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.
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.