How do I make it so that an NPC cannot go to certain areas

How do I make an NPC that cannot go to certain areas e.x spawn point. Thanks you very much! :pray:

Note: I have very little scripting skills, and I have searched for tutorials to help me but I don’t understand Sorry for inconvenience

if NPC.HumanoidRootPart.CFrame == Vector3.new(x,y,z) then

NPC.Humanoid.MoveToPoint = Vector3.new(x,y,z)

end
2 Likes

you’re supposed to use pathfinding modifers BUT they’re in beta. So they don’t work outside of studio :(. So i’d recommend making a custom path. Use this game as a refrence. Feel free to use the scripts and stuff.
Custom path test.rbxl (64.9 KB)

1 Like

Does this work with large areas?

Region3 | Roblox Creator Documentation can be used for that or you could check if they are touching an invisible part

1 Like

Is there a script to make it so if it is touching a part it will go the other way or something? (Maybe it can teleport back somewhere)

I am on iPad, i’ll test that out when I can

if table.find(NPC.RightFoot:GetTouchingParts(),"DontTouch") then

NPC.Humanoid:MoveTo(Alabama)

end
3 Likes

He said he doesn’t have much scripting knowledge. He probably doesn’t understand what half the things do in this script.

1 Like

He could search it up on the api

1 Like

Put part name here? Should I do

PartName.workspace here?

Yes put the parts actual name there

1 Like

Do I need to reference it? Or just part name is alright?

Part name is alright but you have to put quotes around it

1 Like
local part = workspace:FindFirstChild("Part") --change to name of part

part.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("HumanoidRootPart") then
		local hmr = hit.Parent.HumanoidRootPart
		hmr.CFrame = CFrame.new(0, 0, 0)
	end
end)

Simple script which teleports you back to 0, 0, 0 when you touch a part. It’s a server script, please it in ServerScriptService, and make sure the name of the part is valid.