Problem with collision groups

So, i have this grabbing system that using collision groups to prevent flying with the object that you are grabbing. So since i cant use the same collision group name per player, i have to create a new one each time someone grabs an object. This works and all, but once you get above 32 collision groups, it gives an error; Cannot create more than 32 collision groups. which is not good. How do i work around this?

I guess i could create 1 collision group name per player, but i don’t know how i could do that.

Some help will be very much appreciated!

RS = game:GetService("ReplicatedStorage")
Players = game:GetService("Players")
PhysicsService = game:GetService("PhysicsService")

GameManager = workspace:WaitForChild("GameManager")
ColisionGroupNumbers = GameManager:WaitForChild("ColisionGroupNumbers")
--ColisionGroupNumbers.Value = ColisionGroupNumbers.Value + 1

Character = script.Parent
Humanoid = Character:WaitForChild("Humanoid")

-- Create two collision groups
PhysicsService:CreateCollisionGroup("Part2_" .. tostring(ColisionGroupNumbers.Value))
PhysicsService:CreateCollisionGroup("CharacterChildren_" .. tostring(ColisionGroupNumbers.Value))

Event = RS:WaitForChild("GrabEvent")

Event.OnServerEvent:Connect(function(player, Bool, CanGrab)
	--print(Bool.ClassName)
	if Bool then
		local Part = Bool.Parent
		if CanGrab then
			Bool.Value = true
			ColisionGroupNumbers.Value = ColisionGroupNumbers.Value + 1
			PhysicsService:CreateCollisionGroup("Part2_" .. tostring(ColisionGroupNumbers.Value))
			PhysicsService:CreateCollisionGroup("CharacterChildren_" .. tostring(ColisionGroupNumbers.Value))
			
			PhysicsService:CollisionGroupSetCollidable("CharacterChildren_" .. tostring(ColisionGroupNumbers.Value), "Part2_" .. tostring(ColisionGroupNumbers.Value), true)
		else
			Bool.Value = false
			--== AntiCollide ==--
			
			-- Add an object to each group
			PhysicsService:SetPartCollisionGroup(Part, "Part2_" .. tostring(ColisionGroupNumbers.Value))
			local children = Character:GetChildren()
			for i, child in ipairs(children) do
				if child:IsA("BasePart") then
					PhysicsService:SetPartCollisionGroup(child, "CharacterChildren_" .. tostring(ColisionGroupNumbers.Value))
				end
			end
			
			 
			PhysicsService:CollisionGroupSetCollidable("CharacterChildren_" .. tostring(ColisionGroupNumbers.Value), "Part2_" .. tostring(ColisionGroupNumbers.Value), false)
			--== End of anti collide ==--
		end
	end
end)

In this case I see 2 main groups:

  1. objects you can grab
  2. players who can grab these objects

In order to prevent players from being able to collide with objects they can grab, they have to be put into a different collision group which is not collidable with the collisiongroup of the draggable objects

local physicsService = game:GetService("PhysicsService")

physicsService:CreateCollisionGroup("draggableParts")
physicsService:CreateCollisionGroup("playerGroup")
physicsService:CollisionGroupSetCollidable("draggableParts", "playerGroup", false)

Set all players into the same collisiongroup named “playerGroup” and all draggable parts in the collisiongroup draggableParts

1 Like

Is there a way to set individual parts to collide with players? cause i want it so i can release an object, and it the object collidable again.

EDIT: Also this doesn’t seem to be disabling the collision too:

RS = game:GetService("ReplicatedStorage")
physicsService = game:GetService("PhysicsService")

GrabCollisionGroupEvent = RS:WaitForChild("GrabCollisionGroupEvent")

physicsService:CreateCollisionGroup("DraggableParts")
physicsService:CreateCollisionGroup("PlayerGroup")
physicsService:CollisionGroupSetCollidable("DraggableParts", "PlayerGroup", false)

GrabCollisionGroupEvent.OnServerEvent:Connect(function(player, Part, Collidable)
	if Part then
		if not Collidable then
			print("Setted collision to false")
			physicsService:SetPartCollisionGroup(Part, "DraggableParts")

		else
			
		end
	end
end)

I believe you can just set collision groups on the client, which won’t replicate to the server, so only that client wouldn’t be able to collide with the object.

1 Like