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

Playing an animation on a button press?

Hello, i was trying to get an animation playing when the button f is pressed, but i can't get it to work, can anyone help?

2 comments

0

I am confused, an animation on an object, or an animation for the character who presses f?

0

Basically, when a player presses f the player should do an animation.

1 answer

You would need to use UserInputService to check when the player has pressed a key on their keyboard. Insert a localscript in starterplayerscripts


local player = game.Players.LocalPlayer

local anim = Instance.new("Animation") -- creating a new animation
anim.AnimationId = script.Parent.anim -- setting the animationID


game:GetService("UserInputService").InputBegan:Connect(function(input, event) -- calling the roblox service
	if input.KeyCode == Enum.KeyCode.F and not event then -- if the key pressed is F
		local playAnim = player.Character:WaitForChild("Humanoid"):LoadAnimation(anim) -- load the animation into the humanoid
		playAnim:Play() -- play the animation
	end
end)

But in this future this is not a website to request scripts its a website to help fix broken ones or answer questions to things you can't comprehend

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