Collision Groups not working?

local PhysicsService = game:GetService("PhysicsService")
local Players = game:GetService("Players")

PhysicsService:RegisterCollisionGroup("Ball")
PhysicsService:RegisterCollisionGroup("Player")

PhysicsService:CollisionGroupSetCollidable("Ball","Player",false)

local ballFolder = workspace:WaitForChild("Balls")

local function onCharacterAdded(character)
	for _,part in pairs(character:GetDescendants()) do
		if part:IsA("BasePart") then
			part.CollisionGroup = "Player"
		end
	end
end

local function onPlayerAdded(player)
	player.CharacterAdded:Connect(onCharacterAdded)

	if player.Character then
		onCharacterAdded(player.Character)
	end
end

for _,part in pairs(ballFolder:GetChildren()) do
	part.CollisionGroup = "Ball"
end

for _,player in pairs(Players:GetPlayers()) do
	onPlayerAdded(player)
end

Players.PlayerAdded:Connect(onPlayerAdded)

ballFolder.ChildAdded:Connect(function(child)
	child.CollisionGroup = "Ball"
end)

1 Like