Collision Group

Hello I working with Collisiongroups, and I want to change the players collision group when they join using a Server Scirpt:

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(char)
		local Sound = Instance.new("Sound", char:FindFirstChild("HumanoidRootPart"))
		
		Sound.Name = "Music"
		Sound.Looped = true
		for i,v in ipairs(char:GetChildren()) do
			if v:IsA("BasePart") or v:IsA("MeshPart") then
				PhysicService:SetPartCollisionGroup(v, "Player")
			end
			break
		end
		
	end)
end)

I tried to use this but the game said to me that it’s deprecated, I’ve never used Collision group since today, so what have I to do to change the player Collisiongroup ?

(I created a collision group called “Player”)

Maybe this will help:

-- // VARIABLES
-- / Services
local PhysicsService = game:GetService("PhysicsService")
local Players = game:GetService("Players")

-- / Collision Groups
local groupName = "Group"
PhysicsService:RegisterCollisionGroup(groupName)

-- // MAIN
Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		for _, child : BasePart in ipairs(character:GetChildren()) do
			if not child:IsA("BasePart") then
				continue
			end
			
			child.CollisionGroup = groupName
		end
	end)
end)

okay it works, but only for HumanoidRootPart, is it correct ?

If it is only working for the HumanoidRootPart, you can add on to the line that checks the child’s class. Earlier you added v:IsA("MeshPart) to your condition. So, that may resolve this issue.

for _, child in ipairs(character:GetChildren()) do
    if not child:IsA("BasePart") and not child:IsA("MeshPart") then
        continue
    end

    -- The rest of the code.
end

it still working only for the HumanoidRootPart, I also tried to change the world

This is not happening for me. Is the character model you are using different from the default? What classes are the other body parts in your character?

Also, maybe you need to add a task.wait() before looping through the children – the character may not have fully loaded. Adding a print() statement to know the children that are being looped through might be helpful, too.

I’m using my Roblox character for the tests, I’m trying to test with play here

OK. Then try adding a task.wait() before looping through the character’s children.
If you still have the break in your code, you should remove it.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.