generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: attempted to index a nil value

Previous Thread :: Next Thread 
Dad_Bot is not online. 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 is not online. 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 is not online. 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 is online. 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 is not online. 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
BunnyBoy26 is not online. BunnyBoy26
Joined: 17 Jun 2010
Total Posts: 5674
17 Jul 2017 05:48 PM
@TimeTicks

Took the words right out of my mouth lol.
Report Abuse
LaeMVP is online. 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 is not online. 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 is not online. 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
BunnyBoy26 is not online. BunnyBoy26
Joined: 17 Jun 2010
Total Posts: 5674
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 is not online. 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 is online. LaeMVP
Joined: 24 Jun 2013
Total Posts: 4416
17 Jul 2017 05:58 PM
Connect :C
Report Abuse
TimeTicks is not online. 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 is online. 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 is not online. Dad_Bot
Joined: 27 Jun 2011
Total Posts: 917
17 Jul 2017 06:02 PM
thanks!


Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image