Okay, so you cannot set a model to a collision group. You can only add BaseParts to a collision group. I have answered something similar on https://scriptinghelpers.org/questions/94958/i-have-a-question-how-can-i-make-a-part-that-only-certain-other-parts-can-collide-with#87731
If you want, take a look at it.
So to do this you have to do it for every descendant.
01 | workspace.ChildAdded:Connect( function (plays) |
03 | if plays:FindFirstChild( "Humanoid" ) then |
06 | for k,part in next ,plays:GetDescendants() do |
08 | if part:IsA( "BasePart" ) then |
10 | physicsService:SetPartCollisionGroup(part, "Players" ) |
Done, but this is not accurate and is a bad practice. Why? This is because there can be dummies and NPCs on the workspace, it's better to use .CharacterAdded wich detects whenever a player gets a new character. This is good to use since it also gives the Character model to be used.
So to implement this you would have to do this
1 | local Players = game:GetService( "Players" ) |
3 | Players.PlayerAdded:Connect( function (Player) |
5 | Player.CharacterAdded:Connect( function (Character) |
Now we script it so it adds to the Collision Group
01 | local Players = game:GetService( "Players" ) |
03 | Players.PlayerAdded:Connect( function (Player) |
05 | Player.CharacterAdded:Connect( function (Character) |
07 | for k,part in next ,Character:GetDescendants() do |
09 | if part:IsA( "BasePart" ) then |
11 | physicsService:SetPartCollisionGroup(part, "Players" ) |
It should be done like that, now if you want you can add a descendantAdded event wich makes sure everything is set
01 | local Players = game:GetService( "Players" ) |
03 | Players.PlayerAdded:Connect( function (Player) |
05 | Player.CharacterAdded:Connect( function (Character) |
07 | for k,part in next ,Character:GetDescendants() do |
09 | if part:IsA( "BasePart" ) then |
11 | physicsService:SetPartCollisionGroup(part, "Players" ) |
17 | Character.DescendantAdded:Connect( function (Part) |
19 | if Part:IsA( "BasePart" ) then |
21 | physicsService:SetPartCollisionGroup(Part, "Players" ) |
Done! Now it should be working like a charm!
This is the final code.
01 | local physicsService = game:GetService( "PhysicsService" ) |
03 | physicsService:CreateCollisionGroup( "Players" ) |
04 | physicsService:CreateCollisionGroup( "Ball" ) |
06 | local ball = game.Workspace [ "Premier League Ball" ] |
08 | physicsService:SetPartCollisionGroup(ball, "Ball" ) |
10 | physicsService:CollisionGroupSetCollidable( "Players" , "Ball" , false ) |
12 | local Players = game:GetService( "Players" ) |
14 | Players.PlayerAdded:Connect( function (Player) |
16 | Player.CharacterAdded:Connect( function (Character) |
18 | for k,part in next ,Character:GetDescendants() do |
20 | if part:IsA( "BasePart" ) then |
22 | physicsService:SetPartCollisionGroup(part, "Players" ) |
28 | Character.DescendantAdded:Connect( function (Part) |
30 | if Part:IsA( "BasePart" ) then |
32 | physicsService:SetPartCollisionGroup(Part, "Players" ) |
Have fun!
If this answered yor question accept the answer!