Zkiller11
|
  |
| Joined: 25 Aug 2009 |
| Total Posts: 2914 |
|
|
| 27 Sep 2013 09:35 PM |
| How do I prevent the code from breaking when it doesn't exist? |
|
|
| Report Abuse |
|
|
Arkose
|
  |
| Joined: 26 May 2013 |
| Total Posts: 745 |
|
|
| 27 Sep 2013 09:36 PM |
Use an if statement.
~ắṝḱờṧἓ |
|
|
| Report Abuse |
|
|
Zkiller11
|
  |
| Joined: 25 Aug 2009 |
| Total Posts: 2914 |
|
|
| 27 Sep 2013 09:40 PM |
I did. It returns this output:
Workspace.Map Vote:13: attempt to index a nil value |
|
|
| Report Abuse |
|
|
shawnyg
|
  |
| Joined: 21 Apr 2011 |
| Total Posts: 1428 |
|
|
| 27 Sep 2013 09:41 PM |
| Paste the line with the error here. |
|
|
| Report Abuse |
|
|
Zkiller11
|
  |
| Joined: 25 Aug 2009 |
| Total Posts: 2914 |
|
|
| 27 Sep 2013 09:44 PM |
Line 13:
if cac then
Line above it:
local cac = v.PlayerGui:FindFirstChild("Create-A-Class",true):GetChildren() |
|
|
| Report Abuse |
|
|
shawnyg
|
  |
| Joined: 21 Apr 2011 |
| Total Posts: 1428 |
|
|
| 27 Sep 2013 09:48 PM |
| When you put ",true", did you define true? |
|
|
| Report Abuse |
|
|
Zkiller11
|
  |
| Joined: 25 Aug 2009 |
| Total Posts: 2914 |
|
|
| 27 Sep 2013 09:48 PM |
| Why would you ever have to define true lol |
|
|
| Report Abuse |
|
|
|
| 27 Sep 2013 09:50 PM |
true is a default bool value... same as any float or int values. You dont have to define it. Otherwise programming would be impossible
a = 1
Output: Attempt to index a nil value( "1") on line 1 of game.Workspace.script
user: How do i define 1????! |
|
|
| Report Abuse |
|
|
shawnyg
|
  |
| Joined: 21 Apr 2011 |
| Total Posts: 1428 |
|
|
| 27 Sep 2013 09:52 PM |
try if cac==true then. That's all I got. Pretty a "off" day for my scripting..
~Hope I helped, if you need a script, PM me first then buy this when I tell you to: http://www.roblox.com/My-Script-Shirt-item?id=118961994~ |
|
|
| Report Abuse |
|
|
Zkiller11
|
  |
| Joined: 25 Aug 2009 |
| Total Posts: 2914 |
|
|
| 27 Sep 2013 09:53 PM |
What
that's unnecessary as if cac then automatically checks if it exists |
|
|
| Report Abuse |
|
|
shawnyg
|
  |
| Joined: 21 Apr 2011 |
| Total Posts: 1428 |
|
|
| 27 Sep 2013 09:56 PM |
Wait, why did you put "true"?
~Hope I helped, if you need a script, PM me first then buy this when I tell you to: http://www.roblox.com/My-Script-Shirt-item?id=118961994~ |
|
|
| Report Abuse |
|
|
|
| 27 Sep 2013 09:57 PM |
| Why not use pcall() if you're too lazy to put ifs. |
|
|
| Report Abuse |
|
|
Zkiller11
|
  |
| Joined: 25 Aug 2009 |
| Total Posts: 2914 |
|
|
| 27 Sep 2013 10:45 PM |
"Wait, why did you put "true"?"
Because I don't want it to be false? |
|
|
| Report Abuse |
|
|
blocco
|
  |
| Joined: 14 Aug 2008 |
| Total Posts: 29474 |
|
|
| 27 Sep 2013 10:47 PM |
use find first child to see if child exists then use that child |
|
|
| Report Abuse |
|
|
|
| 27 Sep 2013 11:05 PM |
If your variable isn't there, it will throw an error because you attempt to use a method ('GetChildren') on a nil value.
Define the variable first, use an 'if' statement to see if the variable is not nil, and then redefine the variable. |
|
|
| Report Abuse |
|
|
Zkiller11
|
  |
| Joined: 25 Aug 2009 |
| Total Posts: 2914 |
|
|
| 28 Sep 2013 09:44 PM |
Okay, the issue is no longer that it doesn't know if it exists or not, but now this for loop is trolling me. It keeps looping over and over... What am I doing wrong?
local MapVote = workspace:FindFirstChild("Pick a map n00b") local players = game.Players:GetChildren() local m2 = MapVote:Clone() for i,v in ipairs (players) do m2.Parent = v.PlayerGui
-- Loops over and over if the create-a-class Gui does not exist
|
|
|
| Report Abuse |
|
|
|
| 28 Sep 2013 09:45 PM |
local mypart = workspace:findFirstChild("bleh")
if (mypart ~= nil) then mystuff = mypart:GetChildren() -- perform GetChildren() after checking if it exists -- code end |
|
|
| Report Abuse |
|
|
Zkiller11
|
  |
| Joined: 25 Aug 2009 |
| Total Posts: 2914 |
|
|
| 28 Sep 2013 09:47 PM |
| y u no read latest post b4 posting |
|
|
| Report Abuse |
|
|
|
| 28 Sep 2013 09:53 PM |
| My bad. Just trying to help. |
|
|
| Report Abuse |
|
|
Zkiller11
|
  |
| Joined: 25 Aug 2009 |
| Total Posts: 2914 |
|
|
| 28 Sep 2013 09:55 PM |
| That's fine; I just fixed that issue and was wondering why my for loop was trolling me. |
|
|
| Report Abuse |
|
|
Zkiller11
|
  |
| Joined: 25 Aug 2009 |
| Total Posts: 2914 |
|
| |
|
janthran
|
  |
| Joined: 15 May 2009 |
| Total Posts: 17429 |
|
|
| 28 Sep 2013 10:29 PM |
local exists=parent:FindFirstChild("isitthere") if exists then print("it's here") end
if not exists then print("lol where'd it go") end |
|
|
| Report Abuse |
|
|
janthran
|
  |
| Joined: 15 May 2009 |
| Total Posts: 17429 |
|
|
| 28 Sep 2013 10:32 PM |
oh you figured it out sorry I can't help with for loops |
|
|
| Report Abuse |
|
|
Zkiller11
|
  |
| Joined: 25 Aug 2009 |
| Total Posts: 2914 |
|
|
| 28 Sep 2013 10:34 PM |
| y doesn't anybody read the posts b4 posting/ |
|
|
| Report Abuse |
|
|
janthran
|
  |
| Joined: 15 May 2009 |
| Total Posts: 17429 |
|
|
| 28 Sep 2013 10:37 PM |
My way's better anyway. What's with all these people using ~=nil when just leaving it out does the same thing |
|
|
| Report Abuse |
|
|