I'm trying to make a crouching script that will play while the player is moving, and will pause while the player isn't. The animation is stuck being paused no matter what happens, and output shows no errors. Here's the script
Player = game.Players.LocalPlayer repeat wait() until Player.Character local Mouse = Player:GetMouse() local char = game.Workspace[Player.Name] local crouching = false local Animation = script.Anim local animtrack = char.Humanoid:LoadAnimation(Animation) game:GetService("UserInputService").InputBegan:Connect(function(input,proc) if proc == false and input.KeyCode == Enum.KeyCode.C and crouching == false then crouching = true animtrack:Play() char.Humanoid.WalkSpeed = 10 if char.Humanoid.Running == false then animtrack:AdjustSpeed(0) elseif char.Humanoid.Running == true then animtrack:AdjustSpeed(1) end else if proc == false and input.KeyCode == Enum.KeyCode.C and crouching == true then crouching = false animtrack:Stop() char.Humanoid.WalkSpeed = 16 end end end)
Thanks if you can help!
You were correct in somehow using Humanoid.Running to check when the humanoid moves, but that is not how you would do it. It's an event, so you would :Connect() it into a variable in your InputBegan, replacing the if.
You would create an empty local variable; local Event
at the top of your script so the else can access it and disconnect it.
Event = Humanoid.Running:Connect(function(speed) if speed == 0 then animtrack:AdjustSpeed(0) else animtrack:AdjustSpeed(1) end end)
and then, to disconnect the event, you would put this after animtrack:Stop():
Event:Disconnect()
This will prevent the Running event from firing any longer until you press C again.
The original problem with your script was that you were checking if Humanoid.Running
was false, which it isn't, as it's a RBXScriptSignal, which was why it was only stopping the animation (I'm actually not sure why it was returning false). Your code was also only checking once, so if it did somehow work, it would run only once.