HudButton
Provides properties and functions to interact with a button in the HUD.
Properties
id
Gets the unique identifier (ID) for the button. This property is read-only.
position
Gets or sets the position (Vector2).
anchor
Gets or sets the position anchor (Vector2).
pivot
Gets or sets the pivot (Vector2).
fontSize
Gets or sets the size of the font.
foregroundColor
Gets or sets the Color of the foreground.
backgroundColor
Gets or sets the Color of the background.
borderColor
Gets or sets the Color of the border.
textColor
Gets or sets the Color of the text.
borderRounded
Gets or sets a boolean that controls whether the border is rounded.
text
Gets or sets the text content.
Functions
onClick(button, callback)
Assigns a function that should be called whenever the button is clicked.
Example
local button = HudButton.new({
text = 'My Button',
position = Vector2.new(0, -100),
anchor = Anchor.top,
pivot = Pivot.top,
backgroundColor = Color.new(255,0,0),
textColor = Color.white,
})
function onButtonClick(clientId)
-- This function will be called whenever it is clicked by a player
-- The 'clientId' parameter will contain the ID of the player that
-- clicked the button
end
HudButton.onClick(button, onButtonClick)
setText(button, text, target)
Sets the text content.
Example
local button = HudButton.new({
text = 'My Button',
position = Vector2.new(0, -100),
anchor = Anchor.top,
pivot = Pivot.top,
backgroundColor = Color.new(255,0,0),
textColor = Color.white,
})
function onPlayerJoin(player)
-- Customize the button shown to this player
-- E.g. for a player named Bob, this will set the text to "Bob's Button"
HudButton.setText(button, player.name .. "'s Button", player)
end
setVisibility(button, visible, target)
Sets the visibility.
Example
local button = HudButton.new({
text = 'My Button',
})
function onPlayerJoin(player)
-- Wait 5 seconds, then show the button to this player
Task.wait(5)
HudButton.setVisibility(button, true, player)
end
function onStart()
-- Hide the button for all players, by default
HudButton.setVisibility(button, false, Players.All)
end