I want to shorten my script by making one of those things: local buttons = script.Parent.Parent.Button1 I also want to be able to use buttons for Button2 and Button3. How do I have multiple things under one local thingy?
Thanks, - Sam4550
You're looking for tables. You can put
local buttons={script.Parent.Parent.Button1,script.Parent.Parent.Button2,script.Parent.Parent.Button3}
and then, later on use
buttons[1] buttons[2] buttons[3]
Of course, there are better way to do this. To shorten your code more, you can do
local container=script.Parent.Parent local buttons={container.Button1,container.Button2,container.Button3}
Or
local buttons={} for i=1,3 do buttons[i]=script.Parent.Parent["Button"..i] end
Or, if the buttons are the only thing in the container,
local buttons=script.Parent.Parent:GetChildren()
Then, later on, instead of repeating code 3 times, you can do
for number,button in pairs(buttons) do button.Text="Example" end
If you're having trouble understanding that last bit, you can read about the generic for loop.