How to keep NPC inside of area / Random Position inside area

Hello, I was wondering how I would make, let’s say an NPC random walk script but keep the NPC inside of a contained area. Like so he wouldn’t walk too far off. Or like how would I generate a random position inside of an area. Thank you, BMWLux

To generate a random position inside of an area, you would use math.random(). If you were trying to change the x value, you would take two parts and place them in opposite corners of the area.

It would be

local Xval = math.random(corner1, corner2)
local Yval = height -- whatever height you want to keep it at.
local Zval = math.random(corner1, corner2)
Blank.Position = Vector3.new(Xval, Yval, Zval)
-- height is assuming you're keeping the same height level.

Sorry if I could not answer your entire question.

2 Likes