I'm trying to make an animation be toggled when I press 'c' on the keyboard. The character does the animation, but won't stop when I press C again...
The player is supposed to crouch and do it till I press C again:
wait(0.1) local player = game.Players.LocalPlayer local Mouse = player:GetMouse() Anim = script.Animation Toggle = false if Toggle == false then Mouse.KeyDown:connect(function(key) if key == "c" then player.Character.Humanoid.WalkSpeed = 0 player.Character.Humanoid.JumpPower = 0 s = player.Character.Humanoid:LoadAnimation(Anim) Toggle = true s:Play() end end) end if Toggle == true then Mouse.KeyDown:connect(function(key) if key == "c" then player.Character.Humanoid.WalkSpeed = 16 player.Character.Humanoid.JumpPower = 50 s = player.Character.Humanoid:LoadAnimation(Anim) Toggle = false s:Stop() end end) end
Try this:
wait(0.1) local player = game.Players.LocalPlayer local Mouse = player:GetMouse() Anim = script.Animation local s = player.Character.Humanoid:LoadAnimation(Anim) Toggle = false Mouse.KeyDown:connect(function(key) if key == "c" then if Toggle == true then player.Character.Humanoid.WalkSpeed = 16 player.Character.Humanoid.JumpPower = 50 Toggle = false s:Stop() elseif Toggle == false then player.Character.Humanoid.WalkSpeed = 0 player.Character.Humanoid.JumpPower = 0 Toggle = true s:Play() end end end)