|
| 07 May 2014 09:56 PM |
| So, I need to find out if an object has GetMass() (or really Size) as one of its properties. I tried getmetatable(workspace.BasePlate) as a test, but I got an error saying that this metatable is locked. Any suggestions? I may just be over thinking it |
|
|
| Report Abuse |
|
|
Seranok
|
  |
| Joined: 12 Dec 2009 |
| Total Posts: 11083 |
|
|
| 07 May 2014 10:28 PM |
you should use the IsA method:
if object:IsA("BasePart") then -- do something end |
|
|
| Report Abuse |
|
|
MettaurSp
|
  |
| Joined: 20 Mar 2010 |
| Total Posts: 3179 |
|
| |
|
|
| 08 May 2014 05:44 AM |
@mettaursp
Thanks I completely forgot about pcall after all these years. |
|
|
| Report Abuse |
|
|
ajmhm1111
|
  |
| Joined: 22 Jun 2013 |
| Total Posts: 164 |
|
|
| 08 May 2014 09:33 AM |
Hello
local function hasProp(inst,prop) local _,msg = ypcall(function() inst[prop] = inst[prop] end) return ((msg == nil) or (msg:find("not a valid member") == nil)) end;
Example: print(hasProp(Workspace.Part,"Anchored")) --> True
print(hasProp(game.StarterGui.ScreenGui.Frame,"AbsoluteSize")) --> True
print(hasProp(Workspace.Part,"Dancing")) --> false
Hope this helped
--ajmhm1111 |
|
|
| Report Abuse |
|
|
stravant
|
  |
 |
| Joined: 22 Oct 2007 |
| Total Posts: 2893 |
|
|
| 08 May 2014 11:35 AM |
Please don't use pcall for that. You're just throwing away cycles like they grow on trees doing that.
IsA is absolutely the correct way to be checking for the existence of a field on a class. There's only a couple of obscure cases I can think of that you can't handle that way. |
|
|
| Report Abuse |
|
|
MettaurSp
|
  |
| Joined: 20 Mar 2010 |
| Total Posts: 3179 |
|
| |
|