I was looking through the function dump page, and saw pcall. When I tried testing it as so, I get
'Baseplate' is not a valid member of Workspace
Don't think I'm misspelling anything wrong.
When I put in BasePlate
, it prints yes
I'm trying to test the condition with an object that doesn't exist
1 | oExists = function (thing) |
2 | local success,msg = pcall ( function () return thing ~ = nil end ) |
3 | if success then |
4 | return true |
5 | end |
6 | return false |
7 | end |
8 | print (oExists(workspace [ "Baseplate" ] ) and "yes" or "no" ) |
The problem is this part:
1 | workspace [ "Baseplate" ] |
If there is no object named "Baseplate" in Workspace, that statement will error, as you are attempting to reference a nil value outside of the protected call. To make this function work as you would like it to, you could do something like this:
1 | local oExists = function (directory, thing) |
2 |
3 | local success = pcall ( function () return not not directory [ thing ] end ) |
4 |
5 | return success |
6 |
7 | end |
8 |
9 | print (oExists(workspace, "Baseplate" ) and "yes" or "no" ) |
But honestly, you could just use directory:FindFirstChild(string object_name), which is much easier.