I am making this game where I want NPCs to move randomly in a circular area and I wanted to know if there is a more convenient way to do this than I did? Basically I made a bunch of bricks and used math.random to make the NPC go to a random brick and put those bricks in the circle. I want to know if there is a way to make the NPC move randomly in a constructed circular area and not limited to the points I make.

local NPC = game.Workspace.NPC
local pathdeterminer

while true do
 pathdeterminer = "p" .. math.random(1,6)
	if(pathdeterminer == "p1") then
	 NPC.Humanoid:MoveTo(game.Workspace.Points.p1.Position)
	 NPC.Humanoid.MoveToFinished:Wait()
	end
	if(pathdeterminer == "p2") then
 	NPC.Humanoid:MoveTo(game.Workspace.Points.p2.Position)
 	NPC.Humanoid.MoveToFinished:Wait()
	end
	if(pathdeterminer == "p3") then
 	NPC.Humanoid:MoveTo(game.Workspace.Points.p3.Position)
 	NPC.Humanoid.MoveToFinished:Wait()
	end
	if(pathdeterminer == "p4") then
 	NPC.Humanoid:MoveTo(game.Workspace.Points.p4.Position)
 	NPC.Humanoid.MoveToFinished:Wait()
	end
	if(pathdeterminer == "p5") then
 	NPC.Humanoid:MoveTo(game.Workspace.Points.p3.Position)
 	NPC.Humanoid.MoveToFinished:Wait()
	end
	if(pathdeterminer == "p6") then
 	NPC.Humanoid:MoveTo(game.Workspace.Points.p4.Position)
 	NPC.Humanoid.MoveToFinished:Wait()
	end
	wait(0.5)
end


4 comments

1

You can use a CFrame instead of a bricks position for MoveTo

0

So what’s the problem? How can we fix it?

0

There isn't a problem really I just wanted to know if there is a better way to script what I want to do

1

CFrame would work.