Collision groups with tables

What will be the best way to include a table of parts with a collision group because I have parts that get cloned and I want them to be cancollide but they fall through parts if they are. (they are not anchored).

You can run through the table with an ipairs loop to change their CollisionGroupId property.

for i,v in ipairs(table) do
    v.CollisionGroupId = --Insert Collision Group ID here.
end

I tried this but it didn’t work. The part kept falling through the map and i have checked to see if the group is correct and the default value is selected. I’m not sure what the problem.

Try using the SetPartCollisionGroup() function of the PhysicsService.

-- I will assume the 'parts' is a pre-defined variable including all parts you
-- want to change the CollisionGroup of.
for i, part in pairs(parts) do
    PhysicsService:SetPartCollisionGroup(part, "CollisionGroupName")
end

This still doesn’t fix it, it still goes through the baseplate.

I would suggest getting the Collision Group Edtior if you don’t have it. It’s perfect for debugging collision groups. I personally use it a lot.

Also, are you sure CanCollide of the parts is set to true?

image

Try using the Collision Group Editor to check if the parts have the correct collision group and that the collisions with other collision groups are correctly set.

image im not sure what is wrong

Do you want ItemGroup to collide with the Default collision group?

i don’t want itemgroup to fall through the map. Im new to this stuff

If that’s the case, it should work fine.

my system:
press f on a cube to pick it up and rightclick to drop it. When it drops then it should do the thing but it doesn’t.

The game is private so I am unable to join.

sorry my bad, i thought i made it public. It is now. its not a pretty ui layout but this is to get it to work

1 Like

Can you send the part of the code that actually drops the item?

DropItem.OnServerInvoke = function(player, itemName)
	local Inventory = player.Inventory
	local item = Inventory:FindFirstChild(itemName)
	if item then
		if item.Value > 0 then
			item.Value = item.Value - 1
			local itemClone = items:FindFirstChild(itemName):Clone()
			print(itemTable)
			table.insert(itemTable, itemClone)
			for i, part in pairs(itemTable) do
				PhysicsService:SetPartCollisionGroup(part, "ItemGroup")
			end
			itemClone.Anchored = false
			itemClone.CanCollide = false
			local itemNotCloneName = items:FindFirstChild(itemClone.Name)
			print(itemNotCloneName)
			itemClone.CFrame = player.Character.HumanoidRootPart.CFrame + player.Character.HumanoidRootPart.CFrame.LookVector * 4
			itemClone.Parent = game.Workspace
			return true
		else
			return false
		end
	end
end ```

Ah, I saw the error already. Remove this line:

itemClone.CanCollide = false

i just noticed that now. that was there before i decided to try and use cancollide stuff.