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

Is there a way to make an NPC randomly move?

Asked by 7 years ago

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

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 lukeb50 631 — 7y
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. rilgundam 65 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

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

0
Move to makes the chracter actualy walk User#17125 0 — 7y
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). User#17125 0 — 7y
0
Oh ok I see what you mean. Thanks so much! rilgundam 65 — 7y
Ad

Answer this question