I’m making a running system w/ stamina for my game, and I have a custom animation for running. The problem is, I don’t know how to make the animation smoothly stop & transition back when it’s finished.
UserInputService.InputBegan:Connect(function(key)
if key.KeyCode == Enum.KeyCode.LeftShift then
Running = true
Character.Humanoid.WalkSpeed = Character.Humanoid.WalkSpeed*2
while Stamina > 0 and Running do
Stamina -= 1
--print(Stamina)
if Stamina == 0 then
script.Parent.StaminaBar.Bar.Visible = false
else
script.Parent.StaminaBar.Bar:TweenSize(UDim2.new(Stamina / 100, 0, 1, 0), "Out", "Linear", 0)
end
wait()
if Stamina == 0 then
Character.Humanoid.WalkSpeed = WalkSpeed
end
end
end -- scripts for this game by @rcw#9877
end)
UserInputService.InputEnded:Connect(function(key)
if key.KeyCode == Enum.KeyCode.LeftShift then
Running = false
Character.Humanoid.WalkSpeed = WalkSpeed
while Stamina < 100 and not Running do
script.Parent.StaminaBar.Bar.Visible = true
Stamina += 1
--print(Stamina)
script.Parent.StaminaBar.Bar:TweenSize(UDim2.new(Stamina / 100, 0, 1, 0), "Out", "Linear", 0)
task.wait()
if Stamina == 0 then
Character.Humanoid.WalkSpeed = WalkSpeed
end
end
end
end)
If anyone could help I would appreciate it!