Allowing only players to go through a wall

Hello Developer Forum.

I was wondering If anyone knows how to make players go through a wall but NPC’s are not allowed through that wall

So The player needs to be able to walk through but the NPC cannot.

– The blue rig is the player and the 2008 looking rig is the NPC –
image

Do I need to name the NPC’s Humanoid something specific? so only Humanoids can walk through? (players)

1 Like

You will want to use PhysicsService to create collision groups.

5 Likes

try this as a local script inside of the wall:

script.Parent.Touched:Connect(function(hit)
if game.Players:FindFirstChild(hit.Parent.Name) or game.Players:FindFirstChild(hit.Parent.Parent.Name) then
script.Parent.CanCollide = false
end
end)
6 Likes

A localscript inside StarterPlayerScripts should do the trick. Just make the part non-collidable locally. The player will be able to go through it, but the NPC should not.

Script:

workspace.Part.CanCollide = false
3 Likes

It works! But one problem.
image
other objects can also go through. it has to be players only. Could I set the CanCollide = false to a team?

Actually, you should just be able to disable collisions between these parts and players by using collision groups.

Read through this guide on the developer hub, and you should be able to apply the same concept to this problem:

1 Like