How do I add a whole player character to a collision group?

I want this script to make it so that the player is assigned a collision group that can pass through the door. The collision group does not work when it is assigned to the HumanoidRootPart, which I believed adding would assign the whole character to the group. I’m not sure how I should assign the whole character or if I am using the collision groups correctly.

local door = script.Parent

local Players = game:GetService("Players")

local PhysicsService = game:GetService("PhysicsService")

local secmember = "Secmember"

door.Touched:Connect(function(hit)
	local player = Players:GetPlayerFromCharacter(hit.Parent)
	if player then
		if player:IsInGroup(901313) then
			local member = player.Character:FindFirstChild("HumanoidRootPart")
			member.CollisionGroup = secmember
		end
	end
end)

image

As a note for the solution, make sure you do the group check during the playerAdded function.

1 Like

An example of this is already given in the docs: Collisions | Documentation - Roblox Creator Hub

Basically, you’ll need to set the collision group for each part inside the character model.

1 Like

I implemented the code in the doc, but how should I make it so only group members get added?

Add a PlayerAdded event, and then check if the player is in the group, if they are, then a for i,v loop on their character and add any baseparts to the collisiongroup.

If you’re trying to make a group door, I’d recommend just checking if they’re in the group and just set the door’s collision to false (in a local script).

I honestly don’t know why I didn’t think of a local script. Your other solution works to though. Thank you :+1:

Just to be clear, this is what the code should look like?
image

I believe so, yes. Run it and see if it works.

Doesn’t seem to work, still can’t pass through.

It does work when I put it in a normal script, but I believe that would cause the door to remain open as long as there is a member in game

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