I have a problem with this script, and I’m not sure why it’s not working.
(I’m really new to pathfinding)
local pathService = game:GetService("PathfindingService")
local path
local waypoints
game.Players.PlayerAdded:Wait()
game.Players:GetPlayers()[1].CharacterAdded:Wait()
path = pathService:CreatePath()
path:ComputeAsync(script.Parent.UpperTorso.Position, game.Players:GetPlayers()[1].Character.UpperTorso.Position)
waypoints = path:GetWaypoints()
for _, i in pairs(waypoints) do
script.Parent.Humanoid:MoveTo(i.Position)
script.Parent.Humanoid.MoveToFinished:Wait()
end
I’ve updated the script a bit and I get a pathblocked x2 at the start and a few others every now and then, so I think it’s something to do with the moveto
local pathService = game:GetService("PathfindingService")
local path
local waypoints
game.Players.PlayerAdded:Wait()
game.Players:GetPlayers()[1].CharacterAdded:Wait()
local walkAnim = script.Parent.Humanoid:LoadAnimation(script.Parent.Walk)
local jumpAnim = script.Parent.Humanoid:LoadAnimation(script.Parent.Jump)
path = pathService:CreatePath()
path:ComputeAsync(script.Parent.HumanoidRootPart.Position, game.Players.BriefYayyayyay.Character.HumanoidRootPart.Position)
waypoints = path:GetWaypoints()
for _, i in pairs(waypoints) do
if path.Blocked then
print("Path Blocked")
end
if i.Action == Enum.PathWaypointAction.Walk then
script.Parent.Humanoid:ChangeState(Enum.HumanoidStateType.Running)
walkAnim:Play()
elseif i.Action == Enum.PathWaypointAction.Jump then
script.Parent.Humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
jumpAnim:Play()
end
script.Parent.Humanoid:MoveTo(i.Position)
script.Parent.Humanoid.MoveToFinished:Wait()
end