How would using ButtonService benefit you?
Well if you’re someone who likes buttons in their game to feel and look good when interacted with (using animations and sound effects);
You’ve come to the right place because ButtonService makes all of those things so much easier to handle and requires a lot less coding. Though that’s not everything, it can even handle the button’s logic using tasks… we’ll get to that in a bit. It can also animate unlimited amount of objects (can be both UI elements and parts), not just the button itself which you will see in showcase videos.
How does it work?
-
If you simply want all of your buttons to have an animation when interacted with you don’t really need to do much; Just create a LocalScript, put it in PlayerGui/StarterPlayerScripts and copy this line of code,
ButtonService:AutoBindToAnimator(true)
That will automatically assign animations/sound effects to your buttons. -
If you want more control over what buttons get animated and even assign tasks you’d use this,
local binding = ButtonService:BindToAnimator(button, animationData)
Binding is the connection between the animator and the button and it’s also what you’d call the methods on, all of those methods are documented inside of a module script called “Instructions” that can be found inside of the ButtonService module script.
How to create custom animations?
-
If you’re using the
AutoBindToAnimator(true)
method you only need to edit one module script called “DefaultAnimationData” located inside of the ButtonService module script, it also briefly explains how animation data works so you know what to do with it. -
If you want to have different animations for certain buttons you need to create a “AnimationData” module and put it inside of the buttons. Example of an AnimationData module can be found in the example place I linked below.
What are tasks and how to use them?
Tasks are just functions that you can assign to a cartain button’s event (MouseButton1Down, MouseButton1Up, MouseEnter and MouseLeave) There can be unlimited amount of tasks per event.
They can be assigned inside of the “Configuration” module or by using,
binding:AssignTask(mouseInput, function()
-- some function --
end
If you want multiple functions, just wrap them in a table.
SHOWCASE
ButtonService is a module script I initially created because I needed it and this is how I’m using it in an actual game (it’s handling all of the animations, sound effects, visual effects and even the logic for those buttons and simplifies/shortens the code by quite a bit):
Where can I get it?
- You can get the module itself here (includes usage instructions and API) or
- The Usage Example Place which you can edit and see how the stuff shown below is setup: