I am trying to make a list of buttons that all need to execute the same general thing but with slightly different names, cost, among other data. I'm not sure how to put in extra parameters other than who triggered it without writing separate functions. For example:
function onclick(player,GuiObject) -- How can you get the GuiObject print(player.. " clicked ".. GuiObject) end GuiObject.MouseButton1Click:Connect(onclick)
How would I get the GuiObject without writing a function for each event?
You can use a table with the list of buttons and use a for loop to create events for all of them. For example, you can do something like this
local player = game.Players.LocalPlayer local buttons = { -- insert button1, -- insert button2, -- insert button3, -- insert other buttons, } function ButtonClicked(button_clicked) print(player.Name .. " clicked " .. button_clicked.Name) if button_clicked == buttons[1] then -- insert code when button 1 pressed elseif button_clicked == buttons[2] then -- insert code when button 2 pressed elseif button_clicked == buttons[3] then -- insert code when button 3 pressed -- do this for what you want the buttons to do end end for i,v in pairs(buttons) do v.MouseButton1Down:connect(function() ButtonClicked(v) end) end