local player = game.Players.LocalPlayer local Animate local Humanoid = player.Character:FindFirstChild('Humanoid') local UIS = game:GetService("UserInputService") UIS.InputBegan:Connect(function(input,gameProcessed) if input.UserInputType == Enum.UserInputType.Keyboard then if input.KeyCode == Enum.KeyCode.C then if UIS:GetFocusedTextBox() == nil then Humanoid.WalkSpeed = 16 local Animation = Instance.new("Animation", player.Character) Animation.AnimationId = "rbxassetid://03622617391" Animate = Humanoid:LoadAnimation(Animation) Animate:Play() wait() end if input.KeyCode == Enum.KeyCode.C then Animate:Stop() Humanoid.WalkSpeed = 36 end end end end)
This Doesn't Work
P.S. this is a crawling animation
Is there a way so if you click 'C' and it plays the animation(repeating) and if you click 'C' again then it stops?
I have been done this over an hour but I still don't get any ideas.
Ways I Have Tested
-Using BoolValues
--Using Variables
---The one used in the top script
----Use UIS.InputEnded
and about 10 more ways but they all don't work.
One of the issues are- even though I use a while, repeat loop if I stop moving the character the animation cancels.
Can anybody help?
local active = false local player = game.Players.LocalPlayer local Animate local Humanoid = player.Character:FindFirstChild('Humanoid') local UIS = game:GetService("UserInputService") UIS.InputBegan:Connect(function(input,gameProcessed) if input.KeyCode == Enum.KeyCode.C then if UIS:GetFocusedTextBox() == nil then if not active then active = true Humanoid.WalkSpeed = 16 local Animation = Instance.new("Animation", player.Character) Animation.AnimationId = "rbxassetid://03622617391" Animate = Humanoid:LoadAnimation(Animation) Animate:Play() wait(amount of time before you can click again, needs to be atleast 1 second cant be instant or it wont work) active = false end end if input.KeyCode == Enum.KeyCode.C then wait(1) if active then Animate:Stop() Humanoid.WalkSpeed = 36 end end end end)
i think this will work, created a check to see if u had the animation active