Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How would I make a set of buttons in which only one can be selected at a time?

EDIT (what's with the downvotes? Please read the last sentence, I'm not requesting for a script...)

I'm about to go and script a a coffee machine where you select the coffee type in a column of buttons and the flavoring in another column, and the selected buttons would be highlighted in green. But I only want one button to be selected at a time in a column. I've been brain storming ways on how to do this and all my ideas feel too inefficient. How would I go about scripting this? I don't need you to write any scripts of any kind, I would just like to know the basic layout so I know how to organize it as I'm not that great with script organization.

1 answer

✓ Accepted answer

Hey there!

This is just one method I have thought of while reading your question.

While I will not be providing any scripts, take these into consideration:

  • Have a BoolValue inside each button. Use a Changed event to connect to the BoolValue, and whenever it is changed, change the colors. Example:
script.Parent.Selected.Changed:connect(function (onChange)
	if script.Parent.Selected.Value then
		-- Color for selcted
	else
		-- Default color
	end 
end)

You could then have a master script, which would check all the values, and toggle them

An example:

local Buttons = {
script.Parent.Button1,
script.Parent.Button2,
}

function CheckButtons()
	for _,Button in pairs(Buttons) do
		if Button.Selected.Value then
			return true
			Button.Selected.Value = false
		end
	end

	return false
end

for _,Button in pairs (Buttons) do
	Button.MouseButton1Down:connect(function (click)
		CheckButtons()
		Button.Selected.Value = true
	end)
end

#####Note: I've done no testing of this whatsoever. I am actually in economics class while writing this, so please excuse basic mistakes.

This discussion is preserved as it was. New answers, comments, and votes are closed.