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
 

Previous Thread :: Next Thread 
kisamebeast is not online. kisamebeast
Joined: 17 Jan 2008
Total Posts: 3086
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 is not online. 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 is not online. MettaurSp
Joined: 20 Mar 2010
Total Posts: 3179
07 May 2014 10:31 PM
pcall k
Report Abuse
kisamebeast is not online. kisamebeast
Joined: 17 Jan 2008
Total Posts: 3086
08 May 2014 05:44 AM
@mettaursp

Thanks I completely forgot about pcall after all these years.
Report Abuse
ajmhm1111 is not online. 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 is not online. stravant
Forum Moderator
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 is not online. MettaurSp
Joined: 20 Mar 2010
Total Posts: 3179
08 May 2014 05:55 PM
^When there isn't IsA.
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