I am trying to get the script to stop exhausting the .MoveToFinished:Wait() timer! It keeps waiting until the very last moment to finish the movement
I’ve tried to use CHATGPT and searched up for other tutorials or posts online, but nothing has helped!
I’m a bit new to this topic in MoveTo scripting!
local Workspace = game:GetService("Workspace")
local PathfindingService = game:GetService("PathfindingService")
while true do task.wait()
local path = PathfindingService:CreatePath({
AgentRadius = 3,
AgentHeight = 7,
AgentCanJump = false
})
local finishPosition = nil
local RandomPosition = {}
for i,v in pairs(workspace.LEVELS.Level:FindFirstChildWhichIsA("Model"):GetChildren()) do
table.insert(RandomPosition,v.EntityPosition.Position)
end
local random1 = math.random(1,#RandomPosition)
finishPosition = RandomPosition[random1]
-- Compute the path
local success, errorMessage = pcall(function()
local startPosition = script.Parent.Base.Position
path:ComputeAsync(startPosition, finishPosition)
end)
-- Confirm the computation was successful
if success and path.Status == Enum.PathStatus.Success then
-- For each waypoint, create a part to visualize the path
for _, waypoint in path:GetWaypoints() do -- This is what moves it to each waypoint
script.Parent.Humanoid:MoveTo(waypoint.Position)
script.Parent.Humanoid.MoveToFinished:Wait()
end
else
print(`Path unable to be computed, error: {errorMessage}`)
end
end