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

3 comments
Thanks, it works ! But could you tell me how to make a looping animation stop ? It all worked, but my character still stayied in the pose
Let's try that again, I edited it so the animation won't load every single time you press the c key. This time it only loads one and works around it, playing it and stopping it.
If you could accept my answer, that would be nice of you :)