Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to make NPCs choose a path?

So I basically want to make two or more paths and the NPC randomly chooses one of the 2+ paths to follow using parts labelled with letters (A, B, etc...) or numbers (1, 2, 3, etc...).

Below is one of the scripts I wrote for one of my simpler NPCs - Please add to that.


-- WESTWORLD HOST BUILD 1 : SIMPLE WALK PATTERN

model = script.Parent.Parent
hum = script.Parent.Humanoid
torso = script.Parent.Torso
while true do
	if model.PointA ~= nil then
		a = model.PointA
		hum:MoveTo(a.Position, a)
		repeat
			wait(0.1)
		until (a.Position - torso.Position).magnitude <= 5
	else
		print("No Point A.")
	end
wait(0.1)
	if model.PointB ~= nil then
		b = model.PointB
		hum:MoveTo(b.Position, b)
		repeat
			wait(0.1)
		until (b.Position - torso.Position).magnitude <= 5
	else
		print("No Point B.")
	end
wait(0.1)
	if model.PointC ~= nil then
		c = model.PointC
		hum:MoveTo(c.Position, c)
		repeat
			wait(0.1)
		until (c.Position - torso.Position).magnitude <= 5
	else
		print("No Point C.")
	end
wait(0.1)
	if model.PointD ~= nil then
		d = model.PointD
		hum:MoveTo(d.Position, d)
		repeat
			wait(0.1)
		until (d.Position - torso.Position).magnitude <= 5
	else
		print("No Point D.")
	end
wait(0.1)
	if model.PointE ~= nil then
		e = model.PointE
		hum:MoveTo(e.Position, e)
		repeat
			wait(0.1)
		until (e.Position - torso.Position).magnitude <= 5
	else
		print("No Point E.")
	end
wait(0.1)
end

2 comments

0

This isn't a request site. It's mostly for errors encountered while programming. I would consider going to GitHub or something if you want someone to add on to your code.

0

Go find some YouTube tutorials on Pathfinding Service. Also this is not a request site.

1 answer

This discussion is preserved as it was. New answers, comments, and votes are closed.