I’m having trouble with making my Roblox character change and abandon its old path if there is a new obstacle. I did try looking in different forums in the dev forum for this but I seem to not understand still.
What I’ve tried so far:
local pathfidingservice = game:GetService("PathfindingService")
local human = script.Parent:WaitForChild("Humanoid")
local torso = script.Parent:WaitForChild("Torso")
local path = pathfidingservice:CreatePath()
local destenation = game.Workspace.endpathfindingpart
path:ComputeAsync(torso.Position, game.Workspace.endpathfindingpart.Position)
local waypoints = path:GetWaypoints()
for i, 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 + Vector3.new(0,2,0)
part.Anchored = true
part.CanCollide = false
part.Parent = game.Workspace
if waypoint.Action == Enum.PathWaypointAction.Jump then
human:ChangeState(Enum.HumanoidStateType.Jumping)
end
human:MoveTo(waypoint.Position)
human.MoveToFinished:Wait(2)
PathBlocked = path.Blocked:Connect(function(BlockedPath)
if BlockedPath then
i:Disconnect()
path:ComputeAsync(torso.Position, game.Workspace.endpathfindingpart.Position)
local waypoints = path:GetWaypoints()
human:MoveTo(waypoint.Position)
human.MoveToFinished:Wait(2)
print("yo somethin infront of me")
end
end)
end
Btw I’m 1 year of experience with Lua, so I’m kind of new still.
And here is a video showing my problem: