Collision groups hasn't work!

Hello developers!!! :smiley: :smiley::wave:

These days I am programming a weapon which must accommodate the first person and third person, I have almost everything finished, but the first person fails me, because when generating the viewModel of the arms, only the first time the player falls by collision:
https://streamable.com/46aky6
But as you can see at the bottom, it is assigned the collisions of the player, viewModel and objects, being the objects in this case the gun.
Here you can see when I apply the parts to the corresponding collision groups:

--player
for _, v in Pairs(character:GetChildren()) do
	if v:IsA("BasePart") then
		Services.PhysicsService:SetPartCollisionGroup(v, "Player")
	end
end

--items
for _, toolParts in Pairs(m:GetChildren()) do --m is a clone of the object model
	Services.PhysicsService:SetPartCollisionGroup(toolParts, "Items")
end

--viewModel
local des = c:GetDescendants() --c is a clone of the player which I used to make the arms for the viewModel
for _, v in ipairs(c:GetDescendants()) do
	if (not lookup[v.Name] and not v:IsA("CharacterMesh")) then
		v:Destroy()
	elseif v:IsA("BasePart") then
		Services.PhysicsService:SetPartCollisionGroup(v, "ViewModel")
		v.Anchored = false
	end
end

This is the script I used for when it is in first or third person (it is a RenderStepped):

local sway = Modules.Spring.new(V3(), V3(), V3(), 15, 1)
local function weaponHandsRotate(dt)
	local item = PlayerEquiping[LocalPlayer.Name]:FindFirstChild(ItemEquiping)
	if not item then return end
	
	if (currentCamera.Focus.Position - currentCamera.CFrame.Position).Magnitude <= 1 then
		local cf = currentCamera.CFrame * CFangles(sway.p.y, sway.p.x, 0)
		ViewModel.Head.CFrame = cf
		hum.CameraOffset = Vector3.new()
		
		ViewModel.Parent = currentCamera
		item.PrimaryPart.CFrame = ViewModel.RightHand.CFrame * (Items[ItemEquiping]:GetModelCFrame() - Items[ItemEquiping]:GetModelCFrame().Position)
		item.PrimaryPart.WeldItemJoints.Part0 = ViewModel.RightHand
	else
		ViewModel.Parent = Services.ReplicatedStorage
		item.PrimaryPart.CFrame = RightHand.CFrame * (Items[ItemEquiping]:GetModelCFrame() - Items[ItemEquiping]:GetModelCFrame().Position)
		item.PrimaryPart.WeldItemJoints.Part0 = RightHand
		
		local p = HRP.CFrame:toObjectSpace(currentCamera.CFrame).LookVector
		
		LeftShoulder.C0 = CFnew(LeftShoulder.C0.Position)
		RightShoulder.C0 = CFnew(RightShoulder.C0.Position)
		
		waist.C0 = CFnew(0, y, 0) * CFangles(asin(p.Y), -asin(p.X), 0)
	end
end

Does anyone know what’s going on? Thank you for your attention!

1 Like

It can be that when the player select the gun it change the humanoid state to PlatformStand and then fall.
Try using this line the code after selecting the gun:
humanoid:ChangeState(Enum.HumanoidStateType.Running)

2 Likes

Indeed, it is a solution, the problem is that it goes crazy, but I do not think it is very relevant at the moment, what if I see that it still does not solve it is when walking since it goes like lag without having it:
https://streamable.com/lkwrak

1 Like