Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Animation Not Playing On KeyPress?

So I've made a quick script that when I press the letter Q it plays the animation ID I gave it, But On Press when testing it doesn't want to play.

local UserInputService = game:GetService("UserInputService")

UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
	
	if input.UserInputType == Enum.UserInputType.Keyboard then
		
		if input == Enum.KeyCode.Q then
			local Anim = Instance.new("Animation")
			Anim.AnimationId = "rbxassetid://5903616380"
			local track = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(Anim)
			track.Looped = true
			local UserInputService = game:GetService("UserInputService")
			track:Play(.1, 1, 1)
		end
	end
end)

1 comment

0

Line 7 should be input.Keycode

1 answer

✓ Accepted answer

Well, on Line 7, you forgot to index which property you want to use of input. Looking at your code, it looks like you want to use KeyCode. So to fix your problem, you can do :

if input.KeyCode == Enum.KeyCode.Q then

Lemme know if it helps!

This discussion is preserved as it was. New answers, comments, and votes are closed.