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:
function button()
local startbutton = Instance.new("ImageButton")
startbutton.Parent = gui
startbutton.Name = "StartButton"
startbutton.Size = UDim2.new(0, 100, 0, 28)
startbutton.Position = UDim2.new(0, 5, 0, 570)
end
startbutton.Mousebutton1Click: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.

1 comment
The "Local" could be the problem make it a regular variable: startbutton instead of local startbutton