Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would I make it so that my NPC can't leave a certain area?

Asked by
ElBamino 153
3 years ago

Hey scriptinghelpers, I'm currently working on something different than what I was. I was wondering how would I make it so that my NPC can't leave a certain area? For example if my NPCs name was "Zombie" but I didn't want the "Zombie" following players to the SpawnLocation, how would I make it so that "Zombie" would stay in the area I want it too? I'm actually not sure how to do this, so the only sample code I can provide is my kill on touch script. I have parts around the area that I want the "Zombie", I was thinking that I would use a kill on touch script if something but I'm not sure what that something is. Thanks for the help in advance! I really appreciate it. Sorry to bother with a simple question! I'm only here to learn.

This is a script inside of a part.

script.Parent.Touched:Connect(function(hit)
    if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Parent.Name == "Zombie" then--I don't know.
        hit.Parent.Humanoid.Health = 0
    end
end)
0
I tested a few things out and I'm having no luck. ElBamino 153 — 3y

1 answer

Log in to vote
1
Answered by 3 years ago

Maybe Add A Value To The Zombie And Name It And Check It If That Value Is There?

0
That's actually a really good idea, I didn't even think about that. Thank you. ElBamino 153 — 3y
0
Thanks! Did it work? Brioche_Noodle 45 — 3y
Ad

Answer this question