Help me animation playing when key is pressed

Hello, So I need help with a script.
What I need is that when a player holds down the key “C” It changes there walk animation and there standing animation and when they let go on the key “C” it changes back to the normal walk and standing animation.

I have look on devforum and other places and I cant find the solution I need.

Any help is appreciated.

1 Like

I did try looking on there too and I couldn’t find anything.

Read the first link, that’s an introduction to animations. Then read the third link, that’s an introduction to UserInputService (that’s how you detect when they hold the C key), and then read the second, that’s how you play animations. Everything you need is there

And then you just have to combine the UserInputService with the animation play, and it will work

1 Like

I just tried it and it works just the animation is broken.

That’s my friend trying it out me and him are working on a game.

Hey, there’s a few ways to do this. Recently I made a sprinting system for a Horror game I’m working on, I used something like this to check when the player is holding down a key.

Local Script:

local Player = game.Players.LocalPlayer

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Event = ReplicatedStorage:WaitForChild("RemoteEvent")

local UIS = game:GetService("UserInputService")

local key = Enum.KeyCode.C

local function IsKeyDown()
	return UIS:IsKeyDown(key)

	if not IsKeyDown() then
		--whatever you want to happen when the key isnt being held
		print("key isnt being held")
		--whatever you want to happen when the key is being held
		print("key is being held")
1 Like

Quick question, where will this script be inside of? :happy1:

1 Like

Hey, I have it in StarterPlayerScripts.