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

Help Me With Adding Animations To Key Events?

For example, I've been trying to do a flip by pressing the letter "e" I truly don't know how to do this.

1 answer

✓ Accepted answer

All you have to do, using UserInputService, is to bind a certain key, to process and handle the animation.

local player = game:GetService("Players").LocalPlayer
local uis = game:GetService("UserInputService")
local key = "E" -- key to bind

local animation = Instance.new("Animation")
animation.AnimationId = "animation asset id"
local character = player.Character or player.CharacterAdded:wait()

uis.InputBegan:connect(function(inputObject, processed)
	if not processed then
		if inputObject.KeyCode == Enum.KeyCode[key] then
			local humanoid = character.Humanoid
			
			if humanoid then
				local track = humanoid:LoadAnimation(animation)
				track:Play()
			end
		end
	end
end)

EDIT the second parameter to the InputBegan event, gameProcessedEvent, is a boolean value that is set to true if the game itself is processing the input... (ie: chatting).

3 comments

0

Thanks you Soooo Much But it says " play is not a valid member of AnimationTrack" What Do I do?

0

right, it should be "Play".. instead of "play".

0

Thank you So Much!

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