I am trying to make an enemy that will chase the closest player but for some reason it just doesn't work, the thing doesn't move and I had tested before making the script, the thing will move. Here is my script:
local hum = script.Parent.Humanoid
local distance = 20
while true do
for i,v in pairs(game.Players:GetChildren()) do
if v.Character then
local pos = (script.Parent.HumanoidRootPart.Position - v.Character.HumanoidRootPart.Position).magnitude
if pos <= distance then
hum:MoveTo(v.Character.HumanoidRootPart.Position)
end
end
end
wait(5)
end
Can someone help?

2 comments
I think your code is all right good work. Just keep looking!
I just realized why it didn't seem to work 1) I didn't get close enough and 2) I had it to wait 5 afterwards