Character movement not working?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve?
    I have an AI that checks if you’ve gone out of bounds, if you have, it spawns at the closest node and then runs directly towards you. Right now it is not designed to kill you, but to just go to your location.

  2. What is the issue?
    The AI moves in a really, really wierd way, and then just decided it didn’t want to be in this game and ran all the way to the edge of the map and flung itself off.

  3. What solutions have you tried so far?
    I believe I’ve done everything right with parameters, but also I am an idiot so, that is a factor in how things may work. To figure out what it’s doing, I set it to make glowy blocks where it’s going, aswell as an output

local SpookyNodes = game.Workspace.SpookyNodes:GetChildren()

while true do
	print("check")
	wait(5)
	local Players = game.Players:GetChildren()
	for count = 1,#Players do
		local Character = Players[count].Character
		if Character.HumanoidRootPart.Position.X > 1028 or Character.HumanoidRootPart.Position.X < -1028 or Character.HumanoidRootPart.Position.Z > 1028 or Character.HumanoidRootPart.Position.Z < -1028 then
			print("come get yer crunchy boy")
			local Node = SpookyNodes[1]
			for nodecount = 1,#SpookyNodes do
				if (SpookyNodes[nodecount].Position - Character.HumanoidRootPart.Position).Magnitude > (Node.Position - Character.HumanoidRootPart.Position).Magnitude then
					Node = SpookyNodes[nodecount]
				end
				script.Parent.HumanoidRootPart.Position = Node.Position
				print(script.Parent.HumanoidRootPart.Position)
				script.Parent.HumanoidRootPart.Music:Play()
				script.Parent.HumanoidRootPart.Music.ReverbSoundEffect.WetLevel = 0
				
				wait(5)
				script.Parent.Humanoid:MoveTo(Character.HumanoidRootPart.Position, Character.HumanoidRootPart)
				local Update = 0
				wait(3)
				script.Parent.HumanoidRootPart.Anchored = false
				while Character.HumanoidRootPart.Position.X > 1028 or Character.HumanoidRootPart.Position.X < -1028 or Character.HumanoidRootPart.Position.Z > 1028 or Character.HumanoidRootPart.Position.Z < -1028 and Character.Humanoid.Health > 0 do
					if Update == 16 then
						script.Parent.Humanoid:MoveTo(Character.HumanoidRootPart.Position, Character.HumanoidRootPart)
						Update = 0
					end
					Update += 1
					print("POS: " .. tostring(script.Parent.HumanoidRootPart.Position))
					print("TARGET: " .. tostring(Character.HumanoidRootPart.Position))
					print("DISTANCE: " .. tostring((script.Parent.HumanoidRootPart.Position - Character.HumanoidRootPart.Position).Magnitude))
					local Part = game.ReplicatedStorage.Storage.StrangePart:Clone()
					Part.Parent = game.Workspace
					Part.Position = script.Parent.HumanoidRootPart.Position
					wait(0.5)
				end
			end
		end
	end
end