Collision groups broken

A game i’m currently making uses this collision group script. It works, but the collision groups 3 and 4 are swapped, and if i try to change the order, they don’t work. Any reason why? The script broke very suddenly, it was working previously.

```
phs = game:GetService("PhysicsService")

local def='Default'
local plr='Player'
local other='OtherPlayers'
local collidewplrs='OnlyCollideWithPlayers'
local nocollidewplrs='DoNotCollideWithPlayers'
phs:CreateCollisionGroup(plr)
phs:CreateCollisionGroup(other)
phs:CreateCollisionGroup(collidewplrs)
phs:CreateCollisionGroup(nocollidewplrs)
phs:CollisionGroupSetCollidable(plr,other,false)
phs:CollisionGroupSetCollidable(def,other,false)
phs:CollisionGroupSetCollidable(collidewplrs,other,false)
phs:CollisionGroupSetCollidable(nocollidewplrs,other,false)
phs:CollisionGroupSetCollidable(collidewplrs,def,false)
phs:CollisionGroupSetCollidable(collidewplrs,nocollidewplrs,false)
phs:CollisionGroupSetCollidable(plr,nocollidewplrs,false)
```

You can manualy create your collision groups ^^
Go to the “Model” Tab and click “Collision Groups”

1 Like

Will this allow collision groups to be toggled in the properties tab?

You don’t need to create so much collision groups to disable the collision between players.

  1. Click the “Model” Tab
  2. Click the “Collision Group” button at the right side
  3. Create a new group, rename it “Players”
  4. Change the values like this:
    Capture
  5. Add a script in the ServerScriptService
  6. Write this code inside it:
local PhysicsService = game:GetService("PhysicsService")
local Players = game:GetService("Players")
local playerCollisionGroupName = "Players"
local previousCollisionGroups = {}

local function setCollisionGroup(object)
	if object:IsA("BasePart") then
		previousCollisionGroups[object] = object.CollisionGroupId
		PhysicsService:SetPartCollisionGroup(object, playerCollisionGroupName)
	end
end

local function setCollisionGroupRecursive(object)
	setCollisionGroup(object)

	for _, child in ipairs(object:GetChildren()) do
		setCollisionGroupRecursive(child)
	end
end

local function resetCollisionGroup(object)
	local previousCollisionGroupId = previousCollisionGroups[object]
	if not previousCollisionGroupId then return end 

	local previousCollisionGroupName = PhysicsService:GetCollisionGroupName(previousCollisionGroupId)
	if not previousCollisionGroupName then return end

	PhysicsService:SetPartCollisionGroup(object, previousCollisionGroupName)
	previousCollisionGroups[object] = nil
end

local function onCharacterAdded(Character)
	setCollisionGroupRecursive(Character)
	Character.DescendantAdded:Connect(setCollisionGroup)
	Character.DescendantRemoving:Connect(resetCollisionGroup)
end

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

Players.PlayerAdded:Connect(onPlayerAdded)

Now the collision between all players is disabled and you always can toogle the “Players” collision value to true or false in game if needed

Should have clarified, but the collision group’s main problem is the player and part collision. Collision group 3 is supposed to only allow player collisions with parts, and collision group 4 is meant to only allow part to part collisions.