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 ?
-- // 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)
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
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.