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: How to avoid this error?

Previous Thread :: Next Thread 
DigitalVeer is not online. DigitalVeer
Joined: 23 Jun 2009
Total Posts: 4182
25 Feb 2015 08:16 PM
oExists = function(thing)
local success,msg = pcall(function() return thing ~= nil end)
if success then
return true
end
return false
end

print(oExists(workspace["Baseplate"]) and "yes" or "no")

Don't feel like I misspelled 'BasePlate', I'm trying to test with a nil object.
However, I get the expected 'Baseplate is not a valid member of Workspace' error.

Any thoughts on how to fix?
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
25 Feb 2015 08:31 PM
There is no reason for pcall right there. It does the same thing to do this.

oExists = function(thing)
return thing ~= nil
end

print(oExists(workspace["Baseplate"]) and "yes" or "no")
Report Abuse
DigitalVeer is not online. DigitalVeer
Joined: 23 Jun 2009
Total Posts: 4182
25 Feb 2015 08:32 PM
@Jarod, I tried that originally at first, but then switched to pcall to try and get around the error.
Report Abuse
TooKawaiiForSenpai is not online. TooKawaiiForSenpai
Joined: 03 Mar 2009
Total Posts: 3241
25 Feb 2015 08:33 PM
Ayy so a common error with new scripters is trying to index a thing that doesn't exist.

Try using Workspace:FindFirstChild("Thing") on things that you dont know if they exist. I'tll return nil

Doing Workspace["Thing"] on something that doesnt exist will error -- avoid it
Report Abuse
DigitalVeer is not online. DigitalVeer
Joined: 23 Jun 2009
Total Posts: 4182
25 Feb 2015 08:38 PM
Yes, but not everything I'm checking for will be in Workspace.
I know I can just use :FindFirstChild() on objects, but it's not going to work in every scenario as wanted
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