Using a Variable that was defined in a function?
Asked by
6 years ago Edited 6 years ago
Hi, I'm having trouble since I would like to use a variable that I have defined inside a function that I called. Here is an example from my code:
2 | local startbutton = Instance.new( "ImageButton" ) |
3 | startbutton.Parent = gui |
4 | startbutton.Name = "StartButton" |
5 | startbutton.Size = UDim 2. new( 0 , 100 , 0 , 28 ) |
6 | startbutton.Position = UDim 2. new( 0 , 5 , 0 , 570 ) |
9 | startbutton.Mousebutton 1 Click:connect(newfunction) |
Now, I can't use the variable startbutton outside of the function, which makes sense since the function is where I defined it. Is there a way to be able to use this variable again? Or are there any workarounds? On a side note, I've already tried using WaitForChild to wait for the new Image Button to appear, and it doesn't seem to be working as it stops the script and nothing happens.