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

Toggle animation script wont work?

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

--ANIMATIONS--
local pushupanim = Instance.new("Animation")
pushupanim.AnimationId = "http://www.roblox.com/asset/?id=316736671"

local jumpanim = Instance.new("Animation")
jumpanim.AnimationId = "http://www.roblox.com/asset/?id=316760136"


mouse.KeyDown:connect(function(key)
    if key == "h" then
        local playAnim = humanoid:LoadAnimation(pushupanim)
        playAnim:Play()
        humanoid.WalkSpeed = 0
        On = true
    elseif key == "h" and 
        On == true 
        then
        local playAnim = humanoid:LoadAnimation(pushupanim)
        playAnim:Stop()
        humanoid.WalkSpeed = 16
    end
end)

It's supposed to play on H and stop if pressed again, but it only plays it and when I press it again it just plays again.

1 answer

Log in to vote
0
Answered by 8 years ago

When you press H, the first part will run no matter what, so that's why you need to check if On is false

mouse.KeyDown:connect(function(key)
    if key == "h"  and On == false then
        local playAnim = humanoid:LoadAnimation(pushupanim)
        playAnim:Play()
        humanoid.WalkSpeed = 0
        On = true
    elseif key == "h" and 
        On == true 
        then
        local playAnim = humanoid:LoadAnimation(pushupanim)
        playAnim:Stop()
        humanoid.WalkSpeed = 16
    end
end)
Ad

Answer this question