Dropdown
Pick one option, or several. Searchable, with three selection styles.
The smallest dropdown#
main:Dropdown({
Text = "Target mode",
Options = { "Nearest", "Lowest HP", "Random" },
Callback = function(choice)
targetMode = choice
end,
})choice is the selected string.
My Script
v1.0
Mode
Building it up#
Pick a starting option:
main:Dropdown({
Text = "Target mode",
Options = { "Nearest", "Lowest HP", "Random" },
Default = "Nearest",
Callback = setTargetMode,
})Let the user choose several — Callback now receives an array:
main:Dropdown({
Text = "Targets",
Multi = true,
Options = { "Nearest", "Lowest HP", "Highest HP", "Random" },
Default = { "Nearest" },
Callback = function(list)
print(table.concat(list, ", "))
end,
})My Script
v1.0
Rooms
Add a search box — worth it once the list passes about ten items:
main:Dropdown({
Text = "Player",
Options = playerNames,
Search = true,
SearchPlaceholder = "Find a player…",
Callback = selectPlayer,
})Selecting multiple#
Click a row to toggle it. Hold shift and click to select a whole range — and the range is added to what you already had, so shift never throws away your existing picks.
Three styles decide how a selected row looks:
main:Dropdown({ Text = "Rooms", Multi = true, Style = "check", Options = rooms })
main:Dropdown({ Text = "Rooms", Multi = true, Style = "fill", Options = rooms })
main:Dropdown({ Text = "Rooms", Multi = true, Style = "outline", Options = rooms })| Style | Selected rows get |
|---|---|
check | A tick box on the left. The clearest, and the default for multi. |
fill | A translucent accent background across the row |
outline | An accent border around the row |
Every option#
| Option | Type | Default | What it does |
|---|---|---|---|
Textreq | string | — | The label. |
Optionsreq | string[] | — | The list to choose from. |
Callback | function | — | Receives a string, or an array of strings when Multi is set. |
Default | string | string[] | — | Starting selection. Use an array when Multi is set. |
Multi | boolean | false | Allow more than one selection. |
Style | string | "check" | check, fill or outline — how a selected row is drawn. |
Search | boolean | false | Adds a filter box inside the menu. |
SearchPlaceholder | string | — | Ghost text for that filter box. |
Placeholder | string | — | Shown when nothing is selected. |
Open | boolean | false | Start with the menu open. |
Icon | string | — | An icon shown before the label. |
Description | string | — | A quieter second line. |
HoverColor | Color3 | — | Overrides the row hover tint. |
HoverFill | number | — | How strongly a hovered row fills, 0 to 1. |
Save | string | — | Persist the selection under this key. |
Methods#
| Method | What it does |
|---|---|
Get() | The current value — a string, or an array when Multi |
Set(value) | Selects a value or list of values, and fires Callback |
SetOptions(list) | Replaces the option list in place |
Open() / Close() / IsOpen() | Controls the menu |
Show() / Hide() / SetVisible(bool) | Shows or hides the whole control |
Destroy() | Removes it from the page |
Rebuilding the list at runtime#
A player list changes constantly. SetOptions swaps the contents without
rebuilding the control:
local target = main:Dropdown({
Text = "Target player",
Options = {},
Search = true,
Callback = setTarget,
})
local function refreshPlayers()
local names = {}
for _, player in ipairs(game.Players:GetPlayers()) do
table.insert(names, player.Name)
end
target:SetOptions(names)
end
game.Players.PlayerAdded:Connect(refreshPlayers)
game.Players.PlayerRemoving:Connect(refreshPlayers)
refreshPlayers()SetOptions clears the shift anchor
Swapping the list resets where a shift-range would measure from — an anchor pointing at row 8 of a list that now has four rows would select a range that does not exist.