Box That Only Collides With NPC

Hello everyone,

I am currently making a game where the NPC is protecting a weapon inside of a box and the player needs to get it, meaning the player can collide with the box and the NPC can not. How can I do that? I tried adding CollisionGroups but I am really confused on how it works. Does anyone have more info or other ways I can do it? Thank you!

Go to the collision configurator and make it look something like this

Then you use SetPartCollisionGroup and assign the corresponding group to each object

Source: Collision Filtering
A plugin that you can use for the NPC and the box: Collision Group Editor - Roblox

2 Likes

Thank you so much! Ill try the plugin

How to I make a collision group for the players?

In the roblox editor: open it and at the bottom it says “Add Group”, you write a word and press enter.

In the plugin: in the plugin bar these buttons will appear, press “Add Collision Group” and type a word in the box that will appear and press enter.
image

2 Likes

Yeah but how will it know that it is a collision group for players? Sorry if im missing something.

What does the game know that it is a group for players? The game does not know, so you must make a script for that, here something simple.

for _,Part in pairs(script.Parent:GetDescendants()) do
	if not Part:IsA("BasePart") then		continue			end
	game:GetService("PhysicsService"):SetPartCollisionGroup(Part, "Players")
end

Put it in a Server Script and put it in StarterCharacterScripts.

2 Likes

Got it! Thank you so much for the help!!!