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

How do I insert an animation into a button?

I've made an animation GUI, I have the buttons and all, but I need to know how to insert the animation into the button

1 answer

Hi!

For this you will need to use the MouseButton1Click Event. Once the button is clicked, it will then call code inside the function. Then you will need to use the LoadAnimation function for the player's humanoid. It will then load the animation inside the character, but it won't play until you command it.

local button = --Put the button here.
local player = game.Players.LocalPlayer

local anim = Instance.new("Animation") --Creates a new animation.
anim.AnimationId = "http://www.roblox.com/Asset?ID=[ANIMATIONIDHERE]" --Put the AnimationId in the brackets.

button.MouseButton1Click:connect(function() --The button was clicked, release the kraken!
	local animation = player.Character.Humanoid:LoadAnimation(anim) --Loads the animation inside the character's humanoid.
	animation:Play() --Plays the animation.
end)

This script must be put in a LocalScript, because this is a client-side action for the player.

Click Accept Answer if this was what you're looking for! Comment if you have any different concerns!

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