Im trying to make a script that runs a in pairs loop to make buttons do functions but then a smaller size
heres my problem if I add () to put the variables in it will run the code and start an error so I cant do that but I also dont want to make more functions just to change a few things inside of it. Im using tables to keep it shorter
local function ChosenMap(title, button, back)
ChosenTitle1.Text = title
ChosenTitle2.Text = title
button.UIStroke.Color = Color3.new(0.333333, 0.666667, 0.498039)
button.ImageColor3 = Color3.new(0.333333, 0.666667, 0.498039)
back.UIStroke.Color = Color3.new(0, 0, 0)
back.ImageColor3 = Color3.new(1, 1, 1)
end
local button1Ups = {
[StartButton] = StartGame,
[TutorialButton] = ChosenMap
}
thats a small part of the code that you might need for a solution keep in mind that I cant add () to the chosenmap to choose a value for the title, button or back
yeah but I still dont get it sorry how is the script supposed to know to which function this info is linked or am I sopped to keep the [button] = DeployToGame and then its linked to that function? bc not all my buttons are supposed to have the same function I just use it to make the script shorter and I supose i can use a if statement but still then I have to change a lot to make that work
I don’t understand what you mean by that? If you need extra data to pass in, you can turn your table into a nested table.
local button1Ups = {
[StartButton] = {StartGame, "Title", StartButton, "Hello!"},
}
for button, data in pairs(button1Ups) do
local func, title, button2, arg3 = table.unpack(data)
func(title, button2, arg3)
end