I’m trying to write a function that moves an npc to a random position, and after getting to that position, waits a second, and runs the function again. The problem is that every thing that I tried hasn’t worked so far. Here’s all the methods I’ve tried:
function EnemyAI:StartSearch(enemy,variable,cooldown,range,offsetpos)
local hum = enemy:FindFirstChild("Humanoid")
local hrp = enemy:FindFirstChild("HumanoidRootPart") or enemy.PrimaryPart
variable = true
local function Move(hrpv,humv)
humv:MoveTo(hrpv.Position + Vector3.new(math.random(-range,range),0,math.random(-range,range)))
humv.MoveToFinished:Connect(function()
wait(cooldown)
Move(hrpv,humv)
end)
end
coroutine.wrap(Move)(hrp,hum)
end
function EnemyAI.StartSearch(enemy,variable,cooldown,range,offsetpos)
local hrp = enemy:FindFirstChild("HumanoidRootPart") or enemy.PrimaryPart
local hum = enemy:FindFirstChild("Humanoid")
variable = true
coroutine.wrap(function()
local restart = true
while restart do
restart = false
hum:MoveTo(hrp.Position + Vector3.new(math.random(-range,range),0,math.random(-range,range)))
hum.MoveToFinished:Connect(function()
wait(cooldown)
restart = true
end)
end
end)
end
function EnemyAI.StartSearch(enemy,variable,cooldown,range,offsetpos)
local hrp = enemy:FindFirstChild("HumanoidRootPart") or enemy.PrimaryPart
local hum = enemy:FindFirstChild("Humanoid")
variable = true
coroutine.wrap(function()
local restart = true
while restart do
restart = false
hum:MoveTo(hrp.Position + Vector3.new(math.random(-range,range),0,math.random(-range,range)))
hum.MoveToFinished:Wait()
hum.MoveToFinished:Connect(function()
wait(cooldown)
restart = true
end)
end
end)
end
I can’t think of anything else to try please help. Thank you in advance.