CollisionGroups Not Working Correctly

Hey, I’m trying to make it so a part with CanCollide set to false can collide with the torsos of players. However, the torsos don’t collide with the part and there are no errors provided.

Here is my code:

local torsos = "Torsos"
local ffcol = "FF"
game:GetService("PhysicsService"):RegisterCollisionGroup(torsos)
game:GetService("PhysicsService"):RegisterCollisionGroup(ffcol)
ff.CollisionGroup = ffcol
for i,v in pairs(game:GetService("Players"):GetPlayers()) do
	if v == plr then
		v.Character.Torso.CollisionGroup = torsos
	end
end
game:GetService("PhysicsService"):CollisionGroupSetCollidable(ffcol, torsos, true)

How do I fix this?

2 Likes

I have CanCollide set to false because I want the part to not collide with anything but players’ torsos. I’ve tried setting CanCollide to true and instead setting its collisions with the “Default” CollisionGroup to false, but it still doesn’t work.

You can directly edit the collision groups in Studio using the Collision Groups tab located at the Model ribbon tab.
If by doing code, you would need to make the group not collide with the “Default” collision group.

I can’t edit it in studio because the part is created in-game via a script, so I have to script the CollisionGroups. And I’ve already set the part to CanCollide (true) and tried making it not collide with the “Default” CollisionGroup; it still didn’t work.

I can’t see the problem here anymore, so I suggest to try checking the part’s collision group, it may or may not be set properly, or the collision group did not actually set the “Default” group off.

Will try to replicate this problem in Studio!

I found a fix now, tested in Studio:

local torsos = "Torsos"
local ffcol = "FF"
local ff = script.Parent

game:GetService("PhysicsService"):RegisterCollisionGroup(torsos)
game:GetService("PhysicsService"):RegisterCollisionGroup(ffcol)

ff.CollisionGroup = ffcol

game:GetService("PhysicsService"):CollisionGroupSetCollidable(ffcol, torsos, true)
game:GetService("PhysicsService"):CollisionGroupSetCollidable(ffcol, "Default", false)

game:GetService("Players").PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		char.Torso.CollisionGroup = torsos
	end)
end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.