Nexus Button - Custom Cross-Platform Button Class

At the beginning of 2017, I open sourced my Button Class from Ultimate Boxing. While it worked for the time, it had some problems, mainly due to the coupling of the text and the button. To go with a new style for user interfaces for me for 2019 and 2020, I decided to rewrite it with more of an OOP mentality. It still retains a lot of the same features, like being able to add a controller icon that is only displayed when a controller is connected.

For example, this sample code:

--Get the button factory and cut frame classes.
local NexusButton = game:GetService("ReplicatedStorage"):WaitForChild("NexusButton")
local TextButtonFactory = require(NexusButton:WaitForChild("Factory"):WaitForChild("TextButtonFactory"))
local CutFrame = require(NexusButton:WaitForChild("Gui"):WaitForChild("CutFrame"))

--Create 2 button factories.
local ConfirmFactory = TextButtonFactory.CreateDefault(,170/255,0))
local CancelFactory = TextButtonFactory.CreateDefault(,0,0))

--Create a ScreenGui and adorn frame.
local ScreenGui ="ScreenGui")
ScreenGui.Parent = script.Parent

local MessageAdorn ="Frame")
MessageAdorn.Size =,0,0.15,0)
MessageAdorn.SizeConstraint = "RelativeYY"
MessageAdorn.Position =,0,0.5,0)
MessageAdorn.AnchorPoint =,0.5)
MessageAdorn.BackgroundTransparency = 1
MessageAdorn.Parent = ScreenGui

--Create the background.
local Background =
Background.BackgroundColor3 =,170/255,1)
Background.BackgroundTransparency = 0.25

local Message ="TextLabel")
Message.Size =,0,0.4,0)
Message.Position =,0,0.3,0)
Message.BackgroundTransparency = 1
Message.TextScaled = true
Message.Text = "Confirm purchase?"
Message.TextColor3 =,1,1)
Message.TextStrokeColor3 =,0,0)
Message.TextStrokeTransparency = 0
Message.Font = "SciFi"
Message.Parent = MessageAdorn

--Create the buttons.
local ConfirmButton = ConfirmFactory:Create()
ConfirmButton.AnchorPoint =,0.5)
ConfirmButton.Position =,0,1,0)
ConfirmButton.Size =,0,0.3,0)
ConfirmButton.SizeConstraint = "RelativeYY"
ConfirmButton.Parent = MessageAdorn

local CancelButton = CancelFactory:Create()
CancelButton.AnchorPoint =,0.5)
CancelButton.Position =,0,1,0)
CancelButton.Size =,0,0.3,0)
CancelButton.SizeConstraint = "RelativeYY"
CancelButton.Parent = MessageAdorn

--Set up the events.


Creates this dialog with no controller connected:

And this dialog when I plug in a controller:

This button class is a lot more complicated than the previous version (which is deprecated now), but addresses the following problems:

  • Properties couldn’t be passed through to buttons easily, leading to a lot of unneeded code
  • TextLabels were always added to the button, whether they are wanted or not
  • No use subclasses, like the original curved frame

With this version, the following features have been added:

  • Buttons can be multiple colors. While not practical, it was needed for the backgrounds of the controller icons. All that is needed is to set the BackgroundColor3 or BorderColor3 to a ColorSequence. Make sure to use ColoredCutFrame instead of CutFrame if you aren’t using the button.
  • Rather than mapping a single key to a MouseButton1Down, any key set of keys can be mapped to the MouseButton1 or MouseButton2 events. In the example above, pressing A or B on a controller will trigger the MouseButton1Down events for both buttons.
  • Rather than having only BorderSizePixel or BorderSizeScale, both can be used together.
  • “Factory” classes are included so you can create a single “factory” object with defaults set so you don’t have to set the same properties repeatedly for several buttons.
  • The code is unit tested. A lot of bugs that happened during development have been fixed.

This button will be used in several of my upcoming projects. Feel free to use it for your own.


Nice! This is a bit unrelated to the project itself but…



Made the correction to the example. For some reason at first I was thinking it was something in the GitHub docs rather than this post, which would have required more effort to correct.

1 Like

Second one still says puchrase though.

The second image has been corrected.

I updated the buttons to use UIGradients for multiple colors. Instead of using up to 10 frames per color, there is up to 9 frames for any amount of colors. There are no functional changes, so it is a drop-in replacement for the existing version!

1 Like

Amazing work on this! Might use for my game.

Is there a way to remove the cut frame? The website doesn’t give that much information

What is your goal? If you are trying to make the NexusButton transparent, you can set the BackgroundTransparency and BorderTransparency to 1.

Do you think I can learn how to make cross platform input faster by taking this apart then hunting around for the sparse redundant and limited coverage provided by the develop articles?

Thank you! i forgot to put BorderTransparency to 1