I implemented a walking script that plays an animation when the player moves. But whenever the player stops and starts moving again—or rapidly presses movement keys like W, A, S, or D—the animation snaps back to the beginning instead of continuing smoothly. It makes the animation seem kinda unnatural, any way to fix this?
this example shows me spamming the D key
local walkAnimationId = "117732757115316"
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local walkAnimation = Instance.new("Animation")
walkAnimation.AnimationId = "rbxassetid://" .. walkAnimationId
local walkTrack = humanoid:LoadAnimation(walkAnimation)
humanoid.Running:Connect(function(speed)
if speed > 0 then
if not walkTrack.IsPlaying then
walkTrack:Play()
walkTrack:AdjustSpeed(0.5)
walkTrack:AdjustWeight(1,0.3)
end
else
if walkTrack.IsPlaying then
walkTrack:Stop(0.25)
end
end
end)
local players = game:GetService("Players")
local player = players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait() :: Model
local humanoid = character:FindFirstChildOfClass("Humanoid") :: Humanoid
local animator = humanoid:WaitForChild("Animator") :: Animator
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://117732757115316"
local track = animator:LoadAnimation(animation) :: AnimationTrack
local resetTimeoutTime = 1 :: number
local lastTimePosition = 0 :: number
local lastTimeout = 0 :: number
humanoid.Running:Connect(function(Speed: number)
local currentTime = tick() :: number
if Speed > 0 and not track.IsPlaying then
if currentTime > (lastTimeout + resetTimeoutTime) then
lastTimePosition = 0
end
track:Play()
track:AdjustSpeed(0.5)
track:AdjustWeight(1, 0.3)
track.TimePosition = lastTimePosition
elseif track.IsPlaying then
lastTimePosition = track.TimePosition
lastTimeout = currentTime
track:Stop(0.25)
end
end)