Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

The code cannot stop the looping animation?

Asked by
LIRI1 7
5 years ago

I have this code for a sitting animation, I have a toggle script with it. Its looped in of its own (used an animation Editor) and it works that way. When I press Z, the character sits forever, when I press Z again it's supposed to stand up and keep walking, yet it doesn't!

local player = game.Players.LocalPlayer
repeat wait() until player.Character.Humanoid
local humanoid = player.Character.Humanoid
local mouse = player:GetMouse()
On = false

--ANIMATION--
local pushupanim = Instance.new("Animation")
pushupanim.AnimationId = "http://www.roblox.com/asset/?id=3408464847"
mouse.KeyDown:connect(function(key)
    if key == "z"  and On == false then
        local playAnim = humanoid:LoadAnimation(pushupanim)
        playAnim.Priority = Enum.AnimationPriority.Action
        playAnim:Play()
        humanoid.WalkSpeed = 0
        On = true
    elseif key == "z" and 
        On == true 
        then
        local playAnim = humanoid:LoadAnimation(pushupanim)
        playAnim.Priority = Enum.AnimationPriority.Action
        playAnim:Stop()
        humanoid.WalkSpeed = 16
        On = false
    end
end)

After the "elseif", the Humanoid.WalkSpeed = 16 Does work, yet the animation doesn't stop.

1 answer

Log in to vote
0
Answered by
Joshument 110
5 years ago

The problem here is that both of the playAnims you use are different animations you are loading. This is because these are not global variables and can only be accessed in their respective if statements. The simple fix to this is to just load the animation BEFORE the if statements. If you can't, make a new variable equal to nil, and set it to your loaded animation if it's nil and do nothing if it's not.

0
The animation yet doesn't stop. I tried both methods and the result is still the same. As a mention, its a looping sitting animation. LIRI1 7 — 5y
Ad

Answer this question