So I’m making a GUI that lets you choose weapons, how would I assign each button a function without individually calling each button in a script? The way I’m making the button is, the script checks the name of the button, then checks the item container if said weapon exists then sets the a value to the selected weapon.
I need help assigning a function to each button on my weapon selector
Can you just make the script say “If the button is pressed, set value to selected weapon”?
I could do that but for the sake of efficiency I don’t want my script to be cluttered with over 30 of Button.MouseButton1Click:Connect(Function()
Ok, that’s my only idea for the script so far, sorry.
You could connect this one time with a
for loop. Buuut the times you write
if will be a lot. Depends on results.
You can have a dictionary of functions with the key being the name of the button. Then, as @octav20071 said, loop through the buttons and connect a MouseButton1Click and call the function when the event fires.