How could I use Collision Filtering to make group only doors?

I know how to make the usual group only door using onTouched, but I’m wondering how could I make a group only door using collision filtering. For example a player is added and the script fires making the door no collide because the player’s group rank is above a rank. I also don’t want the event to be global either just for that one player.

1 Like

Take a look at the following article: Collision Filtering

I have, but the article does not really outline how I could fit

game.Players.LocalPlayer:GetRankInGroup(123456790) >= 3

into a Collision Filtering script

Create a collision group for each player with all the player’s parts. Then create a collision group for the door.

if player:GetRankInGroup(123456790) >= 3 then PhysicsService:CollisionGroupSetCollidable(doorcollisiongroup, playercollisiongroup, false) end

Technically, you could pick the hacky route and in a LocalScript determine whether one may go through the door or not and if they can, delete or disable CanCollide on the door within the LocalScript. Though, this is hacky and it’d probably do you more good to use Collision Filtering.

When a character loads in, set the baseparts of the character to be in a collision group where it does not collide with the door.

Is it not easier to just have two collision groups (one for the door and one that doesn’t collide with the door) and set the player’s character parts to be in the “don’t collide with the door” group instead of Default when the check comes out true.

Saves you having to worry about adding and removing collision groups for every player that enters and leaves, which could get messy and depending on player count you could reach the max number of groups easily.

Yes, this method would be better. I did not think of that

Thanks using your ideal to ditch the whole two functions has ended with a final script of;

local PhysicsService = game:GetService("PhysicsService")

local doorcollisiongroup = "GroupDoor"

PhysicsService:CreateCollisionGroup(doorcollisiongroup)
PhysicsService:CollisionGroupSetCollidable(doorcollisiongroup, doorcollisiongroup, false)
PhysicsService:SetPartCollisionGroup(workspace.GroupDoor, doorcollisiongroup)

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		if Player:GetRankInGroup(1234567890) >= 3 then
			for _,v in pairs(Character:GetDescendants()) do
				if v:IsA("BasePart") then
					PhysicsService:SetPartCollisionGroup(v, doorcollisiongroup)
				end
			end
		end
	end)
end)

I used the original suggestion of Scriptide’s door collision, but made it so not every player has a group. Coming out with this whole thing.

(That’s the most compact I was able to make the script off my knowledge)

Yay, but ti does not give the same perks that Collision groups give like have the collision group being for multiple things and how compact they are.

(Also they are just generally cooler)

You could use collection service. Then check it player is in group.

That’s why I said “hacky”, because well, it works but can’t be applied elsewhere.