#Animation bug

1 messages · Page 1 of 1 (latest)

blissful crescent
#

I wrote a script where when a player clamps the LShift, he starts running, after which he spends stamina. I also made a running animation. But when I release LShift, the animation continues to work. How can I fix this?

#

this script:

#

local Player = game.Players.LocalPlayer
local Character = Player.Character
local UserInputService = game:GetService("UserInputService")
local Animation = script.Animation

local stamina = 100
local running = false

stamina = math.clamp(stamina,0,100)

UserInputService.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
local Humanoid = Character:WaitForChild("Humanoid")

    local Anim = Humanoid:LoadAnimation(Animation)
    Anim:Play()
    running = true
    Character.Humanoid.WalkSpeed = 15
    while stamina > 0 and running do
        stamina = stamina - 1
        script.Parent:TweenSize(UDim2.new(stamina / 100,0,1,0), "Out","Linear", 0)
        wait()
        if stamina == 0 then
            Character.Humanoid.WalkSpeed = 3
        end
    end
end

end)

UserInputService.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
local Humanoid = Character:WaitForChild("Humanoid")

    local Anima = Humanoid:LoadAnimation(Animation)
    Anima:Stop()
    running = false
    Character.Humanoid.WalkSpeed = 3
    while stamina < 100 and not running do
        stamina = stamina + 1
        script.Parent:TweenSize(UDim2.new(stamina / 100,0,1,0), "Out","Linear", 0)
        wait()
        if stamina == 0 then
            Character.Humanoid.WalkSpeed = 3
        end
    end
end

end)

formal geyser
# blissful crescent I wrote a script where when a player clamps the LShift, he starts running, after...

you are using :loadanimation every time. this creates a new animation track every time. so when it gets to the inputended and you loadanimation, that new animation track was never playing to start with so doing stop does nothing. fix it by calling loadanimation once, to get one animation track, and then the rest should be easy. though if you used chatgpt to write this you're gonna have a hell of a time trying hehe

blissful crescent
formal geyser
#

getpropertychangedsignal("movedirection

blissful crescent
formal geyser
sterile musk
#

tralarelo tralala

blissful crescent
sterile musk
formal geyser
# sterile musk

heartbeat? and you didn't put the stamina drain in there? bruh

sterile musk
#

😙

blissful crescent
# sterile musk

now my character is fast even without pressing LShift, but when I'm standing, the animation doesn't work.

formal geyser
blissful crescent
echo flowerBOT
#

studio** You are now Level 1! **studio

sterile musk
blissful crescent
#

thats finnaly works