How to make players only collide with players on their own team

Im very new to Collision Filtering so im not very sure on how to make an collision group that collides with nothing except for players on their own team and the “default” collision group (to allow them to collide with floors)

Is this what you’re looking for?

only works for 2 teams, in my game you can create up to 25 teams using a command

Well I’m not an expert regrding the collision stuff so sorry.

Edit: All I can say is using a for loop

Use the physics service, I assume that you don’t have the teams at start of the game. So you can put the code it the “team creation” command.

Use PhysicsService and loop it

local ps = game:GetService("PhysicsService")

function createTeam(name)
 -- You should create your team in here
 ps:CreateCollisionGroup(name) -- Creates new group with new name

 for i,v in pairs(ps:GetCollisionGroups()) do -- Gets all available collision groups
  if game.Teams:FindFirstChild(v.Name) then -- Checks if the group name is same as team name
   ps:CollisionGroupSetCollidable(name, v) -- This will loop and sets all groups to not collide with the team group.


-- let's add same change events
  ps:SetPartCollisionGroup(plr.Character, team) -- changes players group

There are probably typos and errors because I’m writing this on mobile
I hope this will help you.

it returns Argument 1 is missing or nil