Getting Property of Object

I’m making a plugin that converts a model to a script and I’m trying to get the propertys of the object and set it to the property of the actual part.

I can’t just do theobject.y (y is the property)

local button = plugin:CreateToolbar("Model To Script"):CreateButton("Convert", "", "")
local selection = game:GetService("Selection")

	for i,v in pairs(selection:Get()) do
		if v:IsA("Model") then
			local scripta ="Script", workspace)
			for a, b in pairs(v:GetDescendants()) do
					scripta.Source = scripta.Source.."\nlocal o"..a.." ='"..b.ClassName.."', workspace)"
					for d, y in pairs(GetProperties(b)) do
						scripta.Source = scripta.Source.."\no"..a.."."..b.." = "..b.propertythingidk

You can use this little trick:

local propertyToFind = "Transparency"

someBrick[propertyToFind] = 1 --//this actually does work

I’m doing

scripta.Source = scripta.Source.."\no"..a.."."..t.." = "..b[t]

and its outputting

local o1 ='Part', workspace)
o1.Name = screen
local o2 ='SurfaceGui', workspace)
o2.Name = SurfaceGui
local o3 ='TextLabel', workspace)
o3.Name = TextLabel
local o4 ='Part', workspace)
o4.Name = Part
local o5 ='Part', workspace)
o5.Name = Part
local o6 ='UnionOperation', workspace)
o6.Name = Union

(y is now t)

Could you clarify? One-letter identifiers don’t seem to show the example very well.

ok so

t = the property
scripta = the thing its generating
a = the number so the variables dont mix up
b = part its checking

If you’re trying to get all the properties of an Instance, this thread may help:

did you read the post

im trying to get the value of the property of a part because im going through the propertys

Instead of theobject.y try theobject[y], employing @C_Sharper’s suggested trick.

i tried and it just adds the name

Sorry, but I’m confused, what do you mean adds the name?

all it does is
it only adds the name property

local o1 ='Part', workspace)
o1.Name = 'screen'
local o2 ='SurfaceGui', workspace)
o2.Name = 'SurfaceGui'
local o3 ='TextLabel', workspace)
o3.Name = 'TextLabel'
local o4 ='Part', workspace)
o4.Name = 'Part'
local o5 ='Part', workspace)
o5.Name = 'Part'
local o6 ='UnionOperation', workspace)
o6.Name = 'Union'
local index = function(object, key)
    return object[key]
print(pcall(index, object, key))

You can try this on a specific set of properties for all objects or use a switch with IsA to copy over properties for specific classes. You can also use HTTP to get what properties objects have from the wiki or another host.

wait so i removed the pcall and it errors “Script.lua:181: attempt to concatenate userdata with string” but its a part

i added tostring() so it could work

1 Like