Hello, I am working on a pathfinding system for a game, this system runs locally and works fine, now I am working on adding the animations that I had made to the game.
My problem with this is, even though I am getting no errors the animation is still not playing, I am unsure what the problem could be. Below this will be a short version of the code.
-- THIS IS A LOCAL SCRIPT, DOING THE PATHFINDING LOCALLY SEEMED MORE LOGICAL
-- Declare variables for stuff like PathfindingService, Player, Characters (A folder in replicated Storage), ReplicatedStorage
-- Declare animation variables.
function ComputePath(startGoal:Vector3, endGoal:Vector3)
-- Code used to compute the path, then if its success it returns the path
end
function WalkToWaypoint(humanoid:Humanoid, startGoal:Vector3, endGoal:Vector3)
-- This is where the animations will be used
local Animator = humanoid:WaitForChild("Animator")
local RunTrack = Animator:LoadAnimation(RunAnimation)
RunTrack.Priority = Enum.AnimationPriority.Movement
RunTrack.Looped = true
local Path = ComputePath(startGoal, endGoal)
RunTrack:Play()
local Waypoints = Path:GetWaypoints()
local CurrentWaypointIndex = 2 -- the point to go after the first point
local MovedToFinishConnection:RBXScriptConnection
MovedToFinishConnection = humanoid.MoveToFinished:Connect(function(reached)
if reached then -- if the humanoid reached the waypoint within 8 seconds
if CurrentWaypointIndex < #Waypoints then -- if we have not cycle through the last waypoint
CurrentWaypointIndex += 1 -- we increase the index by 1 so that the humanoid moves to the next waypoint
humanoid:MoveTo(Waypoints[CurrentWaypointIndex].Position) -- and the same thing
RunTrack:Play()
if Waypoints[CurrentWaypointIndex].Action == Enum.PathWaypointAction.Jump then
humanoid.Jump = true
end
else -- we cycled the whole path series!
print("Path reached!")
HasFinised = true
MovedToFinishConnection:Disconnect() -- disconnect the unnecessary event to avoid memory leaks
RunTrack:Stop()
end
else -- failed to reach waypoint within 8 seconds, the dummy probably is stuck, so let's recompute it!
MovedToFinishConnection:Disconnect() -- disconnect the unnecessary event to avoid memory leaks
WalkHumanoid(humanoid, StartingPoint.Position, endGoal) -- we are changing our start goal and replacing it to the current position of our dummy instead of reusing the old one
end
end)
humanoid:MoveTo(Waypoints[CurrentWaypointIndex].Position)
if Waypoints[CurrentWaypointIndex].Action == Enum.PathWaypointAction.Jump then
humanoid.Jump = true
end
end
-- More code below, but not relevant to the problem.
I tried finding solutions on Youtube, the DevForum and even the Documentation, but I can’t seem to figure out what the problem is. So I decided to make this post to ask for help.
If you have any other questions just ask and I will see if I can answer them as soon as possible. Thank you for reading, and for your support.