You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
I wanted to achieve a modular pathfinding system
What is the issue? Include screenshots/videos if possible!
The npc does not play the walking animation but rather floats while following the player
code:
module.Walkto = function(StartPos, EndPos, Humanoid, Walkspeed)
local originalwalkspeed = Humanoid.WalkSpeed
if Walkspeed then
Humanoid.WalkSpeed = Walkspeed
end
local path = PFS:CreatePath()
path:ComputeAsync(StartPos, EndPos)
for _, waypoint in pairs(path:GetWaypoints()) do
Humanoid:MoveTo(waypoint.Position)
Humanoid.MoveToFinished:Wait()
end
Humanoid.WalkSpeed = originalwalkspeed
end
im going to assume that you might also want a idle animation, so youll want a reference for both animations, and to play/stop them depending on what is happening
module.Walkto = function(StartPos, EndPos, Humanoid, Walkspeed)
local originalwalkspeed = Humanoid.WalkSpeed
local animator = Humanoid:FindFirstChildOfClass("Animator")
local walkAnimation = Instance.new("Animation")
local idleAnimation = Instance.new("Animation")
walkAnimation.AnimationId = "rbxassetid://WALK_ANIMATION_ID"
idleAnimation.AnimationId = "rbxassetid://IDLE_ANIMATION_ID"
walkAnimation.Name = "Walk"
idleAnimation.Name = "Idle"
local walkAnimTrack = animator:LoadAnimation(walkAnimation)
local idleAnimTrack = animator:LoadAnimation(idleAnimation)
if Walkspeed then
Humanoid.WalkSpeed = Walkspeed
end
local path = PFS:CreatePath()
path:ComputeAsync(StartPos, EndPos)
idleAnimTrack:Stop()
walkAnimTrack:Play()
for _, waypoint in pairs(path:GetWaypoints()) do
Humanoid:MoveTo(waypoint.Position)
Humanoid.MoveToFinished:Wait()
end
walkAnimTrack:Stop()
idleAnimTrack:Play()
Humanoid.WalkSpeed = originalwalkspeed
end
ideally you make the animation stuff outside of the walk function so that you can play and stop other animations in other actions of the module, like when the npc does a different action for them to stop the idle animation, and also not needing to create instances of the animations