So, I have a dummy walk to a part. While he is on the way, I spawn a part in front of him. When his speed is less than 0.1, I reset his path. But his path will only work when I spawn parts on top of the waypoints:
‘Works’
local wpInx = 1
local debounce = true
local PFS = game:GetService("PathfindingService")
local start = game.Workspace.ImportantDummy.HumanoidRootPart
local End = game.Workspace.fred
local hum = game.Workspace.ImportantDummy.Humanoid
local function GOBOI()
print('ruuunnnniiinnnnggg')
game.Workspace.ImportantDummy.HumanoidRootPart:SetNetworkOwner(nil)
path = PFS:CreatePath()
path:ComputeAsync(start.Position, End.Position)
for i,v in pairs(path:GetWaypoints()) do
local fred = Instance.new("Part",workspace)
fred.Position = v.Position
fred.CanCollide = false
fred.Anchored = true
end
if path.Status == Enum.PathStatus.Success then
waypoints = path:GetWaypoints()
wpInx = 1
hum:MoveTo(waypoints[wpInx].Position)
else
--GOBOI()
end
end
GOBOI()
hum.MoveToFinished:Connect(function(reached)
print(reached)
print(wpInx)
print(#waypoints)
if reached and wpInx < #waypoints then
wpInx += 1
if waypoints[wpInx].Action == Enum.PathWaypointAction.Jump then
hum.Jump = true
end
hum:MoveTo(waypoints[wpInx].Position)
end
end)
hum.Running:Connect(function(speed)
if speed < .1 and debounce == true then
debounce = false
print('k')
path:Destroy()
GOBOI()
wait(1)
debounce = true
end
end)
‘Doesn’t work’
local wpInx = 1
local debounce = true
local PFS = game:GetService("PathfindingService")
local start = game.Workspace.ImportantDummy.HumanoidRootPart
local End = game.Workspace.fred
local hum = game.Workspace.ImportantDummy.Humanoid
local function GOBOI()
print('ruuunnnniiinnnnggg')
game.Workspace.ImportantDummy.HumanoidRootPart:SetNetworkOwner(nil)
path = PFS:CreatePath()
path:ComputeAsync(start.Position, End.Position)
--this is what I delete and it doesn't work
if path.Status == Enum.PathStatus.Success then
waypoints = path:GetWaypoints()
wpInx = 1
hum:MoveTo(waypoints[wpInx].Position)
else
--GOBOI()
end
end
GOBOI()
hum.MoveToFinished:Connect(function(reached)
print(reached)
print(wpInx)
print(#waypoints)
if reached and wpInx < #waypoints then
wpInx += 1
if waypoints[wpInx].Action == Enum.PathWaypointAction.Jump then
hum.Jump = true
end
hum:MoveTo(waypoints[wpInx].Position)
end
end)
hum.Running:Connect(function(speed)
if speed < .1 and debounce == true then
debounce = false
print('k')
path:Destroy()
GOBOI()
wait(1)
debounce = true
end
end)
Can anyone tell me what in the world is happening???