Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to get the properties of something?

I was wondering if you can get the properties of something, in this case a part.

thing = game.Workspace.Baseplate

local props = thing:GetProperties()--I know this isn't a thing

for i,v in pairs(props) do
	print("for the property of a(n)"..thing.ClassName..", the name is "..v.Name..
" and the value is "..v.Value)
end

how do i get something like that, but with something that is real(not :GetProperties).

1 answer

✓ Accepted answer

Sad truth

Sad truth is, you can't get these properties without having a reference to every single property that exists within that object. Yes, it is annoying, but it's the only way. For example, if I wanted to print all the properties of a part, I'd first have to store all the existing properties that consists within the Part instance in a table, then iterate that table while indexing the part with a for loop.


Example:

Here's an example of how you could create a function that prints all properties of a part:

-- All consisting properties of the Part instance
local PartProperties = {
    "Size","Transparency","Position","CFrame","Reflectance",
    "Shape","Anchored","BackParamA","BackParamB","BackSurface",
    "BackSurfaceInput","BottomParamA","BottomParamB","BottomSurface",
    "BottomSurfaceInput","BrickColor","CanCollide","CustomPhysicalProperties",
    "Elasticity","Friction","FrontParamA","FrontParamB","FrontSurface",
    "FrontSurfaceInput","LeftParamA","LeftParamB","LeftSurface","LeftSurfaceInput",
    "Locked","Material","ResizeIncrement","ResizeableFaces","RightParamA","RightParamB",
    "RightSurfaceInput","RightSurface","RotVelocity","Rotation","SpecificGravity","TopParamA",
    "TopParamB","TopSurface","TopSurfaceInput","Velocity","Archivable","ClassName",
    "Name","Parent"
}

-- Create a test part
local Part = Instance.new("Part")

-- Returns a table of all the part's properties
local function GetPartProperties(Part)
    local Props = {}
    for i,v in next, PartProperties do
        Props[v] = Part[v]
    end
    return Props
end

-- Iterate the table "GetPartProperties" returns, printing all the part's properties and corrosponding values.
for i,v in next, GetPartProperties(Part) do
    print(i,v)
end

API

If you don't want to write these tables yourself, I'm more than positive there are multiple options. Here's a hierarchy of classes you can use if you create a string parser for it: https://raw.githubusercontent.com/ScriptGuider/First/master/Testing

Hope this helped, let me know if you have any questions.

4 comments

0

So there's no way to get them automatically? Is there a way with http service and the roblox wiki api to do this? Oe is the above really the only way?

0

Also, what does i,v in NEXT mean. is it the same as pairs?

0

There are probably sources that contain this information, but none that I've looked into. I was basically just saying the method for doing this is the same no matter what, even if you had access to an API page

0

Also for the for loop question, I recommend viewing this: http://www.lua.org/pil/7.3.html

This discussion is preserved as it was. New answers, comments, and votes are closed.