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?
Why not use a PathfindingModifier? No coding is necessary.
the npc follows you around, like a zombie npc.
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?
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)
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.
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.
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?
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)
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
Thanks! But where do I put this. I’m pretty new to this stuff.
Just put it as a script in ServerScriptService
It doesn’t seem to be working i’m sort of just sliding off while my characters feet are inside the part
Thanks a lot, this worked on my npc.
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
I thought NPCS were local aswell. Great solution though