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

Is there a way to make an NPC randomly move?

I was thinking about move.random, but I didn't know if that was a thing or not. Please help me.

2 comments

0

When moving the Npc, to the Npcs Position+Vector3.new(math.random(x),math.random(x),math.random(x)) with x being the max distance it can move in 1 direction

0

can I do Position+Vector3.new(math.random(x<=10),(0),math.random(x<=10)) because I want it to move only a certain amount of blocks, but not up.

1 answer

✓ Accepted answer

To Eleborate on lukeb50's explanation, here is a better answer. Just simple changing the position will teleport the Npc randomly, using Move to is a better option.

Npc = --Humaniod of the npc
Npcmoved = false

Npc.MoveToFinished:Connect(function()
Npcmoved = true
end)


while true do
Npcmoved = false

math.randomseed(tick()) --Makes the Randomness truely random



Npc:MoveTo(math.random(x),math.random(0),math.random(x))

repeat
wait(0.1)
until Npcmoved = true
Npcmoved = false

end

3 comments

0

Move to makes the chracter actualy walk

0

Also, I saw in the comments you wanted it to walk in a certain area, heres the solution. First of all find the area you want the npc to walk around in, ie X 1- 10 and Z 5-7. Then in Math.random do. math.random(1,10) and math.ranomd(5,7).

0

Oh ok I see what you mean. Thanks so much!

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