Dad_Bot
|
  |
| Joined: 27 Jun 2011 |
| Total Posts: 917 |
|
|
| 17 Jul 2017 05:41 PM |
why isn't this working?
toggled = false local panel = script.Parent.Parent.BG
script.Parent.MouseButton1Click:connect(function(onClicked) if toggled == false then panel.Visible = true toggled = true end end)
script.Parent.MouseButton1Click:connect(function(onClicked) if toggled == true then panel.Visible = false toggled = false end end)
|
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 17 Jul 2017 05:42 PM |
Make sure the panel object you're referencing exists.
|
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 17 Jul 2017 05:42 PM |
You might have a better bet doing something like this:
local panel = script.Parent.Parent:WaitForChild('BG')
|
|
|
| Report Abuse |
|
|
LaeMVP
|
  |
| Joined: 24 Jun 2013 |
| Total Posts: 4416 |
|
|
| 17 Jul 2017 05:44 PM |
local Toggle = false local Panel = script.Parent.Parent.BG or error("Panel is nil") script.Parent.MouseButton1Click:Connect(function() Toggled = not Toggled Panel.Visible = not Panel.Visible end) |
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 17 Jul 2017 05:46 PM |
"local Panel = script.Parent.Parent.BG or error("Panel is nil")"
Don't do that ever again.
|
|
|
| Report Abuse |
|
|
|
| 17 Jul 2017 05:48 PM |
@TimeTicks
Took the words right out of my mouth lol. |
|
|
| Report Abuse |
|
|
LaeMVP
|
  |
| Joined: 24 Jun 2013 |
| Total Posts: 4416 |
|
|
| 17 Jul 2017 05:50 PM |
What is wrong with that? Besides assigning Panel to whatever error returns |
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 17 Jul 2017 05:51 PM |
The point is to check if the object exists, not error if it doesnt. Thats why WaitForChild should be used here.
|
|
|
| Report Abuse |
|
|
Dad_Bot
|
  |
| Joined: 27 Jun 2011 |
| Total Posts: 917 |
|
|
| 17 Jul 2017 05:52 PM |
still getting the error
17:51:59.553 - ServerScriptService.Script:7: attempt to index a nil value
|
|
|
| Report Abuse |
|
|
|
| 17 Jul 2017 05:56 PM |
Is this script inside a GuiButton (or something that has the MouseButton1Click event)?
...
wait why do you have two connections for the same event? |
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 17 Jul 2017 05:56 PM |
local gui = script.Parent local main = gui.Parent local panel = main:WaitForChild('BG') local toggled = false
gui.MouseButton1Click:connect(function() --dont put the function here toggled = not toggle panel.Visible = toggled end)
|
|
|
| Report Abuse |
|
|
LaeMVP
|
  |
| Joined: 24 Jun 2013 |
| Total Posts: 4416 |
|
| |
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 17 Jul 2017 05:59 PM |
Sorry buddy. I'm never using that ugly looking way.
|
|
|
| Report Abuse |
|
|
LaeMVP
|
  |
| Joined: 24 Jun 2013 |
| Total Posts: 4416 |
|
|
| 17 Jul 2017 06:01 PM |
| But what if they remove support for connect() and they give Connect() a huge update |
|
|
| Report Abuse |
|
|
Dad_Bot
|
  |
| Joined: 27 Jun 2011 |
| Total Posts: 917 |
|
| |
|