Adds hover, press, and release animations to any TextButton. Supports built-in theme presets and fully custom theme tables — no extra instances required.
ButtonService.Init() attaches all mouse event listeners to a TextButton and manages color and scale transitions via TweenService. It handles the edge case where the cursor leaves while the button is held — the button correctly resets on MouseLeave. AnchorPoint is automatically corrected to (0.5, 0.5) so the press-scale tween shrinks from the center.
Properties
ButtonService.Init(script.Parent.MyButton, "primary")
Pass the TextButton instance, a theme name, and optional press/release callbacks. The service takes over from there — no return value is needed for basic usage.
Minimal setup — primary theme
With press and release callbacks
Two presets are included: 'primary' uses the slate-600 palette (the default SlateUI accent), and 'secondary' uses a near-black palette for subtle ghost-style buttons. Both include separate DefaultColor, HoverColor, PressColor, DefaultStroke, and HoverStroke values.
Using the secondary theme
Pass a table directly as the second argument instead of a string. Your table must include the five color keys: DefaultColor, HoverColor, PressColor, DefaultStroke, and HoverStroke — all Color3 values.
Fully custom theme — red destructive button
| Prop | Type | Default | Description |
|---|---|---|---|
| button | TextButton | — | The TextButton instance to attach behavior to. |
| theme | "primary" | "secondary" | table | "primary" | Theme preset name or a custom table with five Color3 fields. Falls back to "primary" if unrecognized. |
| onPress | (button: TextButton) -> ()? | nil | Optional callback fired on MouseButton1Down. |
| onRelease | (button: TextButton) -> ()? | nil | Optional callback fired on MouseButton1Up or MouseLeave-while-pressed. |
The service stores the button's original Size on init and computes a pressedScale at 95% of that size. A shared UserInputService.InputEnded listener ensures the button always resets even if the cursor teleports off-screen. The UIStroke child (if present) is tweened separately for the border color effect.