Search code examples
luaattributesroblox

How to get Size value of a model on roblox


So I'm making a game that involves the use of the

Size

attribute of a Part. However, since Models don't have a Size attribute, so I was wondering how I could get the Size attribute of a Model. I would like an answer that doesn't use another part (Such as a number value) to store it. Thanks!


Solution

  • As you note, Models do not have the Size property, as that is inherited from the BasePart class—which is not an parent class of Model.

    If by "size" of a model you mean the dimensions of its bounding box, the Model class has a member function for that: GetExtentsSize().

    The Roblox reference article, which you can find here, says the following:

    Returns the size of the smallest bounding box that contains all of the BaseParts in the Model. If Model.PrimaryPart exists then the bounding box will be aligned to that part. If a primary part has not been set then the function will chose a part in the model to align the bounding box to. As the the selection of this part is not deterministic it is recommended to set a Model.PrimaryPart to get consistent results with this function.

    Note this function only returns the size of the smallest bounding box, and the developer must employ their own method to obtain the position of the bounding box.

    As this description notes, calling this function for a model without a primary part may produce inconsistent results. When editing something in Roblox Studio, you may have had a model selected, duplicated it, and seen the bounding box of the copy change from that of the original. I imagine this is the kind of inconsistency to which the article is referring.

    There also exists the Model class member function called GetBoundingBox(), which returns a tuple describing the volume that contains all parts of a model. Please note, though, that I came across this function after some quick Googling and I have not had time to see how it works.