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 » Scripting Helpers
Home Search
 

Re: In a situation where something can or cannot exist

Previous Thread :: Next Thread 
Zkiller11 is not online. 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 is not online. Arkose
Joined: 26 May 2013
Total Posts: 745
27 Sep 2013 09:36 PM
Use an if statement.





~ắṝḱờṧἓ
Report Abuse
Zkiller11 is not online. 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 is not online. shawnyg
Joined: 21 Apr 2011
Total Posts: 1428
27 Sep 2013 09:41 PM
Paste the line with the error here.
Report Abuse
Zkiller11 is not online. 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 is not online. 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 is not online. 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
Jetta765214 is not online. Jetta765214
Joined: 22 Oct 2008
Total Posts: 1855
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 is not online. 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 is not online. 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 is not online. 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
snakeboy1111 is not online. snakeboy1111
Joined: 29 Sep 2012
Total Posts: 268
27 Sep 2013 09:57 PM
Why not use pcall() if you're too lazy to put ifs.
Report Abuse
Zkiller11 is not online. 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 is not online. 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
EaterOfServers is not online. EaterOfServers
Joined: 16 Sep 2013
Total Posts: 277
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 is not online. 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
AbsoluteLOL is not online. AbsoluteLOL
Joined: 01 Dec 2012
Total Posts: 3939
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 is not online. Zkiller11
Joined: 25 Aug 2009
Total Posts: 2914
28 Sep 2013 09:47 PM
y u no read latest post b4 posting
Report Abuse
AbsoluteLOL is not online. AbsoluteLOL
Joined: 01 Dec 2012
Total Posts: 3939
28 Sep 2013 09:53 PM
My bad. Just trying to help.
Report Abuse
Zkiller11 is not online. 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 is not online. Zkiller11
Joined: 25 Aug 2009
Total Posts: 2914
28 Sep 2013 10:25 PM
Bumpers
Report Abuse
janthran is not online. 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 is not online. 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 is not online. 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 is not online. 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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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