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)