What I’m trying to achive is to move characters by using MoveTo in cycle, the problem is that too slow characters, start to override position after time out(I mean built in Roblox MoveTo function, which has time out of 8 second as I remember), I tried using Magnitude,maybe I use it in incorrect way in this situation, because characters sometimes just randomly stop moving after certain position.
Script:
for waypoint=1, #waypoints:GetChildren() do
mob.MovingTo.Value = waypoint
humanoid:MoveTo(waypoints[waypoint].Position)
humanoid.MoveToFinished:Wait()
if (mob.HumanoidRootPart.Position - waypoints[waypoint].Position).Magnitude > 1 then
repeat
mob.MovingTo.Value = waypoint
humanoid:MoveTo(waypoints[waypoint].Position)
humanoid.MoveToFinished:Wait()
until ((mob == nil) or ((mob.HumanoidRootPart.Position - waypoints[waypoint].Position).Magnitude > 1))
end
end
local waypoints =
local mob =
local humanoid = mob:WaitForChild("Humanoid")
local rootPart = mob:WaitForChild("HumanoidRootPart")
local waypointReachDistance = 0.5
for i = 1, #waypoints:GetChildren() do
local waypoint = waypoints:GetChildren()[i]
local targetPosition = waypoint.Position
local reachedWaypoint = false
while not reachedWaypoint do
humanoid:MoveTo(targetPosition)
local function checkArrival()
if (rootPart.Position - targetPosition).Magnitude <= waypointReachDistance then
reachedWaypoint = true
end
end
game:GetService("RunService").Heartbeat:Connect(checkArrival) --Check every frame
wait(0.1) -- Prevents excessive CPU usage. Adjust as needed.
local startTime = tick()
while tick() - startTime < 5 and not reachedWaypoint do
wait()
end
if not reachedWaypoint then
break
end
game:GetService("RunService").Heartbeat:Disconnect(checkArrival)
end
end
And yes, this is the answer from the neural network. If it doesn’t work, let me know, I’ll write the code myself
It doesn’t work, as expected, and yeah bro ,I saw you in another post a while ago
Anyway I after fixing this ai code and deleting all unnecessary stuff, it works, but now I got another problem, what if I have bigger character, will there be any problem? Because you have humanoidRootPart’s center in different place and thing I’m not sure about is that faster mobs now stops sometimes for a very small amout of time to check if they reached point.
Current code:
for i = 1, #waypoints:GetChildren() do
local waypoint = waypoints[i]
local waypointReachDistance = 1
local targetPosition = waypoint.Position
local reachedWaypoint = false
local connection = nil
local function checkArrival()
task.wait()
humanoid:MoveTo(targetPosition)
if (rootPart.Position - targetPosition).Magnitude <= waypointReachDistance and mob ~= nil then
print((rootPart.Position - targetPosition).Magnitude)
reachedWaypoint = true
end
end
local connection = game:GetService("RunService").Heartbeat:Connect(checkArrival) --Check every frame
repeat task.wait() until (reachedWaypoint == true)
connection:Disconnect()
end