Veltamax
|
  |
| Joined: 06 May 2012 |
| Total Posts: 368 |
|
|
| 03 Jun 2014 10:28 AM |
I am not understanding why this doesn't work. I want this textbutton, when I click it, to create the frame and move it to the top, and when I click it again, to move back to the bottom, and remove the frame, and to be able to be done as many times as I want. When I test, it will open it and do what I want, but after the frame removes, and I click it again, it says "Can only tween objects in the workspace". My fail-safes are doing the opposite effect... Could someone see what I'm doing wrong?
Code:
script.Parent.MouseButton1Down:connect(function()
if startframe == nil then startframe = Instance.new([[Frame]], script.Parent.Parent) --startframe properties (took out to shorten post) startframe:TweenPosition(UDim2.new(0,0,0,20), [[Out]], [[Back]], .5) elseif startframe ~= nil then --V ERROR V (even though it only should get here if startframe isn't nil) startframe:TweenPosition(UDim2.new(0,0,0,320), [[In]], [[Back]], .5) wait(2) startframe:remove() end end) |
|
|
| Report Abuse |
|
Veltamax
|
  |
| Joined: 06 May 2012 |
| Total Posts: 368 |
|
| |
|
| 03 Jun 2014 10:39 AM |
Is this the whole script? Have you put the startframe variable at the start of the script? If not, then that's the problem, the if and the else are separated. If you created startframe under the "If", then it's only available in "If", the same thing for the "Else".
idk. I hope it helps even just one bit.
|
|
|
| Report Abuse |
|
DataStore
|
  |
| Joined: 07 Feb 2012 |
| Total Posts: 8540 |
|
|
| 03 Jun 2014 10:42 AM |
The remove method simply changes the parent property of startframe to nil, but if you made a reference to it before removing it, it will still exist.
local Frame = Instance.new("Frame", nil) print(Frame == nil) --> false
local Frame print(Frame == nil) --> true
You'd be better off, in my opinion, using FindFirstChild to see if the frame existed or not. |
|
|
| Report Abuse |
|