How to change player character collision group

Hello, I’m trying to make the player walk through npc’s by changing the collsion group. When changing the group of the npc all part’s in the model change groups. When doing the same for the player only the Head and HumanoidRootPart change groups. When manualy clicking the + on the PlayerGroup when selecting my character the collisions work, so anyone know’s how I can change al part’s collisions using scripts ?

What the script does:

What I need it to do:

local PhysicsService = game:GetService("PhysicsService")
 
local defaultGroup = PhysicsService:GetCollisionGroupName(0)
local playerGroup = "PlayerGroup"
local npcGroup = "NPCGroup"
 
PhysicsService:CreateCollisionGroup(playerGroup)
PhysicsService:CreateCollisionGroup(npcGroup)

function game.ReplicatedStorage.Events.SetPhysics.OnInvoke(Type, char)
	if(Type == "npc") then
		for i,v in pairs(char:GetDescendants()) do
	        if (v:IsA("BasePart")) then
				PhysicsService:SetPartCollisionGroup(v, npcGroup)
	        end
	    end
	else
		for i,v in pairs(char:GetDescendants()) do
			if (v:IsA("BasePart")) then
				PhysicsService:SetPartCollisionGroup(v, playerGroup)
			end
	    end
	end
end

PhysicsService:CollisionGroupSetCollidable(playerGroup, npcGroup, false);
PhysicsService:CollisionGroupSetCollidable(playerGroup, playerGroup, true);
PhysicsService:CollisionGroupSetCollidable(npcGroup, npcGroup, false);
PhysicsService:CollisionGroupSetCollidable(playerGroup, defaultGroup, true);
PhysicsService:CollisionGroupSetCollidable(npcGroup, defaultGroup, true);
3 Likes

Anyone who know’s a potential fix ?

1 Like

Here is a handy website page:
https://developer.roblox.com/en-us/articles/Player-Player-Collisions

This will help you understand it more.

1 Like

Thx, I had tried by copying some code but after copying everything I finnaly got it to work :slight_smile:

2 Likes