so I was looking the the path finding tutorial, and trying to make it to when you press right mouse button, a path is created and your character follows the way points of the path.
Currently if you spam right mouse button, tons of paths are created and the character slowly follows every single one.
How would I make it to where when you create a path, the old one is deleted? This is the script (without the hover script, but you can replace hover with mouse.Hit I think)
local destination = nil
Mouse.Button2Down:connect(function() --Moves character to target position
if Mouse.Target~=nil and Hover.Transparency==0 then
destination = Hover
local path = PathfindingService:CreatePath()
path:ComputeAsync(Char.HumanoidRootPart.Position, Hover.Position)
local waypoints = path:GetWaypoints()
for _, waypoint in pairs(waypoints) do
local part = Instance.new("Part")
part.Shape = "Ball"
part.Material = "Neon"
part.Size = Vector3.new(0.6, 0.6, 0.6)
part.Position = waypoint.Position
part.Anchored = true
part.CanCollide = false
part.Parent = game.Workspace
Char.Humanoid:MoveTo(waypoint.Position)
Char.Humanoid.MoveToFinished:Wait()
end
end
end)

2 comments
This doesn't fix your problem, but you could add a debounce to it ?
well that would make it to where you can only create a path every few seconds