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.
workspace.ChildAdded:Connect(function(plays)
if plays:FindFirstChild("Humanoid") then
print("yeshum")
for k,part in next,plays:GetDescendants() do
if part:IsA("BasePart") then
physicsService:SetPartCollisionGroup(part, "Players")
end
end
end
end)
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
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
end)
end)
Now we script it so it adds to the Collision Group
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
for k,part in next,Character:GetDescendants() do
if part:IsA("BasePart") then
physicsService:SetPartCollisionGroup(part, "Players")
end
end
end)
end)
It should be done like that, now if you want you can add a descendantAdded event wich makes sure everything is set
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
for k,part in next,Character:GetDescendants() do
if part:IsA("BasePart") then
physicsService:SetPartCollisionGroup(part, "Players")
end
end
Character.DescendantAdded:Connect(function(Part)
if Part:IsA("BasePart") then
physicsService:SetPartCollisionGroup(Part, "Players")
end
end)
end)
end)
Done! Now it should be working like a charm!
This is the final code.
local physicsService = game:GetService("PhysicsService")
physicsService:CreateCollisionGroup("Players")
physicsService:CreateCollisionGroup("Ball")
local ball = game.Workspace["Premier League Ball"]
physicsService:SetPartCollisionGroup(ball, "Ball")
physicsService:CollisionGroupSetCollidable("Players", "Ball", false)
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
for k,part in next,Character:GetDescendants() do
if part:IsA("BasePart") then
physicsService:SetPartCollisionGroup(part, "Players")
end
end
Character.DescendantAdded:Connect(function(Part)
if Part:IsA("BasePart") then
physicsService:SetPartCollisionGroup(Part, "Players")
end
end)
end)
end)
Have fun!
If this answered yor question accept the answer!
2 comments
May you check my answer uh, please? i spent some time on it
please accept it aa i spent time on it AAAAA