|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|