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 don’t need to create so much collision groups to disable the collision between players.
Click the “Model” Tab
Click the “Collision Group” button at the right side
Create a new group, rename it “Players”
Change the values like this:
Add a script in the ServerScriptService
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.