What's wrong with this crouch script?

Hello! I made a crouch script that is a LocalScript in StarterCharacterScripts but it isn’t working… does anything look wrong with this script?
local player = game.Players.LocalPlayer
local UIS = game:GetService(“UserInputService”)
local Animate
local Humanoid = player.Character:FindFirstChild(‘Humanoid’)

UIS.InputBegan:Connect(function(Key,chat)
if chat then print(“Chat”) return end
if Key.KeyCode == Enum.KeyCode.C then
print(“Clicked C”)
local Animation = Instance.new(“Animation”, player.Character)
Animation.AnimationId = “rbxassetid://6929242508”
Animate = Humanoid:LoadAnimation(Animation)
Animate:Play()
Humanoid.WalkSpeed = Humanoid.WalkSpeed - 9
end
end)

UIS.InputEnded:Connect(function(Key,chat)
if chat then print(“Chat”) return end
if Key.KeyCode == Enum.KeyCode.C then
Animate:Stop()
Humanoid.WalkSpeed = 16
end
end)

I am also using a custom character, not sure if that would affect it. It won’t even print anything though, not even an error, that’s why I’m confused…

What is wrong? The script looks fine, i have two questions:

  1. Does the character play the normal walk animation when pressing W or move keys?
  2. If yes, is the animation priority set to Action?

Yes, the character plays the normal walk animations, however I think I set the animation priority of the crouch to movement, is that wrong?

I just did this script on a normal R6 character and it prints crouching. I am unsure if this is an issue with the script. Animation Priority is probably it.

Ok so you need to know that there is an animation hierarchy

As you can see the Action priority has the highest priority while playing so the walking animation is set to Action (if i remember correctly) so it is played before your crouch animation because it has a highest priority.

Oh thank you, I will try this. The thing that confuses me the most is that it won’t print anything… I feel that if the script is right that it should at least print “Clicked C”. But, I will try changing the priority.

If its not printing “Clicked C” then you have something in ContextActionService binded to that key. This means the check to make sure chat is false is returning instead of proceeding with the rest of the thread.

Just to test that out, I commented out that part of the script, and still nothing is playing or being printed. I’m not sure why.

I just reparented the script to StarterGUI and suddenly now it’s printing. However it still won’t play the animation.

Is it possible the script is being destroyed at all? I honestly have no clue as to why is wouldn’t be working. You could have a script that is destroying anything in the character.

It’s not being destroyed. I just parented it to StarterCharacterScripts again but it won’t print anymore.

Your creating the instance everytime you press c, you should create and load the animation outside of pressing c.

This is true, however the animation is not working in general. Even with it being created only once. When I ran this code on my normal blank world with an R6 character it worked perfectly. There must be an external script interfering.

I’m sorry, just figured it out. I had a conflicting script. At the time I created the game, I didn’t know that you could use a rig by naming it StarterCharacter and putting it in StarterPlayer. So I created this complicated script that gave the player a character every respawn. I apologize for my mistake.