Help On How To Make a Player Only Wall

I want to make an player only wall so only players can walk through it but NPC’s cant. I’ve tried many tutorials but they are not working, Anyone know how to make this?

2 Likes

Why not use a PathfindingModifier? No coding is necessary.

1 Like

the npc follows you around, like a zombie npc.

1 Like

Well, does it use the path-finding service? Or does it use a : MoveTo setup, I can only spitball random ideas without any code provided.

CollisionGroups next?

1 Like

Maybe you can teleport the npc away from the door when they touch it. Here is a code sample I just made. It checks to see if it’s a not a player that touches the wall, then it will check to see if it has a primary part and then will teleport them away by a 100 studs. You can change the number of studs you want the npc to teleport away by.

local wall = script.Parent
local debounce = false

wall.Touched:Connect(function(hit)
	if hit and hit.Parent and debounce == false then
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		if player then
			if not hit.Parent:FindFirstChild("HumanoidRootPart") then return end
			debounce = true
			hit.Parent:SetPrimaryPartCFrame(hit.Parent:FindFirstChild("HumanoidRootPart").CFrame * CFrame.new(0, 0, 100))
			task.wait(1)
			debounce = false
		end
	end
end)
1 Like

I mean you could just make collision groups.

Go to Model > top right corner > click the wrecking ball > you should have a new window opened.

Next just create 3 new groups : Player,NPC,Doors.

Now its just check game.
If you want players to pass through doors just check the door checkbox under players. For NPCs just uncheck it. Its that simple.

2 Likes

like this? But how does it know what thing is in what group?

1 Like

You have to assign the parts to a group using a script or just the menu. Check out the developer hub page for more info.

1 Like

i understand how to put things in different groups now, but how do make a player apart of the player group. I’m assuming its with a script though. Is there any easier way to do it?

1 Like

No, just use a script.

Here’s a script you can use:

--//Services
local Players = game:GetService("Players")
local PhysicsService = game:GetService("PhysicsService")

--//Functions
Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		for i, basePart in ipairs(character:GetChildren()) do
			if basePart:IsA("BasePart") then
				PhysicsService:SetPartCollisionGroup(basePart, "Players")
			end
		end
	end)
end)
1 Like

I think if you set cancollide to the wall to true, and put a local script to make cancollide to false, it will prevent NPCs from going through

To do this, you would put a local script in starter player scripts that has something like

local Wall = workspace.wall — change this to your wall


Wall.CanCollide = false
3 Likes

Thanks! But where do I put this. I’m pretty new to this stuff.

1 Like

Just put it as a script in ServerScriptService

1 Like

It doesn’t seem to be working i’m sort of just sliding off while my characters feet are inside the part

1 Like

Thanks a lot, this worked on my npc.

1 Like

Yeah i was talking about tht only.

We use PhysicsService:SetCollisionGroup(Object,Group)

So for Players and NPCS just do

for i,v in game.Players:GetPlayers() do
for k,g in v.Character do
If g:IsA("BasePart") then
game:GetService("PhysicsService"):SetCollisionGroup(g,"Player")
end
end
end
1 Like

I thought NPCS were local aswell. Great solution though :ok_hand:

2 Likes