Basically, I've made it so that if you hold LCtrl (using UIS) it lets you crouch, but the problem is, the moving-while-crouching-animation plays even when you're not moving. I've made use of GetState() but it doesn't seem to work. Here's the block of code.
-------------------------
----VARIABLES----
-------------------------
local UIS = game:GetService("UserInputService")
local player = game.Player.LocalPlayer
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")
crouched = false
moving = false
--------------------------
----ANIMATIONS----
--------------------------
local crouchedanim = Instance.new("Animation")
crouchedanim.Parent = character
crouchedanim.Name = "CrouchedAnim"
crouchedanim.AnimationId = "rbxassetid://556017"
local crouchedtrack = humanoid:LoadAnimation(crouchedanim)
local crouchmoving = Instance.new("Animation")
crouchmoving.Parent = character
crouchmoving.Name = "MovingCrouchAnim"
crouchmoving.AnimationId = "rbxassetid://551730"
local crouchmovetrack = humanoid:LoadAnimation(crouchedanim)
UIS.InputBegan:Connect(function(key)
if key.KeyCode == Enum.KeyCode.LeftControl then
crouched = true
if not moving then
crouchedtrack:Play()
humanoid.WalkSpeed = 5
elseif moving then
crouchmovetrack:Play()
UIS.InputEnded:Connect(function(key)
if key.KeyCode == Enum.KeyCode.LeftControl then
crouched = false
crouchedtrack:Stop()
crouchmovetrack:Stop()
humanoid.WalkSpeed = 16
humanoid.StateChanged:Connect(function(oldState, newState)
if newState == Enum.HumanoidStateType.Running then
moving = true
else
moving = false
ignore the fact that there are no ends or spacing, i just typed it up here cause i have no time to open roblox studio (and i am 100% sure that that's the exact code)
Basically, the problem here is that the moving-while-crouched animation still plays even when the player is not running. How do I fix this, how do I make it work?

1 comment
the ends would help a little