Greetings! I’m here to ask for assistance once more. I’ve recently figured out how to stop pathways and creates new ones (as before I had difficulties changing paths). Now that I’ve figured out a way I’ve encountered an issue where it gets buggy and I’d assume the reason is because of the Humanoid.MoveToFinished:Wait() and that waits for at least 1 point to finish.
Mouse.Button2Down:Connect(function()
local Target = Mouse.Target
local Character = Player.Character
if Character and Character.PrimaryPart then
if Target:IsDescendantOf(workspace.World.mapAssets) then
visualRing() -- Visuals
local path = PathfindingService:CreatePath()
path:ComputeAsync(Character.PrimaryPart.Position, Mouse.Hit.Position)
local waypoints = path:GetWaypoints()
updatePath:Fire()
local blockedPathEvent
blockedPathEvent = path.Blocked:Connect(function()
blockedPathEvent:Disconnect()
updatePath:Fire() -- Basically stops the movement
end)
spawn(function()
local stop = false
local listener
listener = updatePath.Event:Connect(function()
listener:Disconnect()
stop = true
for _, point in Pairs(workspace.visualAssets.pathPoints:GetChildren()) do
point:Destroy()
end
end)
generateVisualPath(waypoints)
for index, waypoint in Pairs(waypoints) do
if stop then
break
end
Character.Humanoid:MoveTo(waypoint.Position)
Character.Humanoid.MoveToFinished:Wait()
end
end)
end
end
end)
As you can see it glitches a lot in rotation and positioning. So my question would be how would I be able to instantly break that loop and proceed to a new path. Anyways to improve this script would be appreciated. I removed most of the irrelevant code to keep this simple.
I am asking for improvements but my main issue still stands, I just threw in the last line in case the improvements may fix the error or bug (mainly looking for others methods / ways to do this if that will solve the issue)
Try using the :MoveTo() on the humanoid before moving them towards the new path. For example, if I clicked on a new path for the character to walk to. I would first do Character.Humanoid:MoveTo(Character.HumanoidRootPart.Position) so it would essentially cancel out the MoveTo() because it is already in that position. After that, I would then set the MoveTo() to the point where the player pressed. I hope I explained well.
Mouse.Button2Down:Connect(function()
local Target = Mouse.Target
local Character = Player.Character
if Character and Character.PrimaryPart then
if Target:IsDescendantOf(workspace.World.mapAssets) then
visualRing() -- Visuals
local path = PathfindingService:CreatePath()
path:ComputeAsync(Character.PrimaryPart.Position, Mouse.Hit.Position)
local waypoints = path:GetWaypoints()
updatePath:Fire()
local blockedPathEvent
blockedPathEvent = path.Blocked:Connect(function()
blockedPathEvent:Disconnect()
updatePath:Fire() -- Basically stops the movement
end)
spawn(function()
local stop = false
local listener
listener = updatePath.Event:Connect(function()
listener:Disconnect()
stop = true
for _, point in Pairs(workspace.visualAssets.pathPoints:GetChildren()) do
point:Destroy()
end
end)
generateVisualPath(waypoints)
Character.Humanoid:MoveTo(Character.HumanoidRootPart.Position) -- This will basically cancel out the MoveToFinished()
for index, waypoint in Pairs(waypoints) do
if stop then
break
end
Character.Humanoid:MoveTo(waypoint.Position)
Character.Humanoid.MoveToFinished:Wait()
end
end)
end
end
end)
I just added that one line after generateVisualPath(). Try it out.
I like where you are going but now you are going off a little, the good thing is, using your previous method Character.Humanoid:MoveTo(Character.HumanoidRootPart.Position) is the solution, the only thing is that you positioned it in the wrong area. What I did is place it inside the listener. Anyway thanks for your help. You truly have thought outside of the box and helped.
Oh. I was thinking about that too, but I thought it would end up making it worse. Guess not! I learned a few things today. (If I could go on Studio right now I would’ve test and gave you a more in-depth answer.)