I was wondering if anyone could tell me why the humanoid is not moving in this script. It runs the code, but the humanoid doesn’t move.
local targetting = false
local target = nil
local targetdist = nil
local hum = game.Workspace.Pain.Humanoid
local head = game.Workspace.Pain.Head
function targettingDisable()
wait(15)
targetting = false
target = nil
end
function engage()
repeat
print("Engaging")
local randomclosepos = Vector3.new(head.Position.X + math.random(1,45), 0, head.Position.Z + math.random(1,45))
print(hum.Parent.Name)
hum:MoveTo(randomclosepos)
print(randomclosepos)
wait(1)
until targetting == false
end
while wait(1) do
local npchead = script.Parent:WaitForChild("Head")
if targetting == false then
for _, player in pairs(game.Players:GetChildren()) do
local charhead = player.Character:WaitForChild("Head")
local mag = (npchead.Position - charhead.Position).Magnitude
if mag < 100 then
print(mag)
target = charhead.Parent
targetting = true
targetdist = mag
coroutine.resume(coroutine.create(engage))
coroutine.resume(coroutine.create(targettingDisable))
end
end
end
end