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")

button.Click:Connect(function()
	for i,v in pairs(selection:Get()) do
		if v:IsA("Model") then
			local scripta = Instance.new("Script", workspace)
			for a, b in pairs(v:GetDescendants()) do
				pcall(function()
					scripta.Source = scripta.Source.."\nlocal o"..a.." = Instance.new('"..b.ClassName.."', workspace)"
					for d, y in pairs(GetProperties(b)) do
						--print(b)
						scripta.Source = scripta.Source.."\no"..a.."."..b.." = "..b.propertythingidk
					end
				end)
			end
		end
	end
end)

You can use this little trick:

local propertyToFind = "Transparency"

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

I’m doing

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

and its outputting


local o1 = Instance.new('Part', workspace)
o1.Name = screen
local o2 = Instance.new('SurfaceGui', workspace)
o2.Name = SurfaceGui
local o3 = Instance.new('TextLabel', workspace)
o3.Name = TextLabel
local o4 = Instance.new('Part', workspace)
o4.Name = Part
local o5 = Instance.new('Part', workspace)
o5.Name = Part
local o6 = Instance.new('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:
https://devforum.roblox.com/t/api-method-to-easily-get-set-the-properties-of-an-object/7536/3

did you read the post

I ALREADY HAVE IT AAAAAAAAAA
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 = Instance.new('Part', workspace)
o1.Name = 'screen'
local o2 = Instance.new('SurfaceGui', workspace)
o2.Name = 'SurfaceGui'
local o3 = Instance.new('TextLabel', workspace)
o3.Name = 'TextLabel'
local o4 = Instance.new('Part', workspace)
o4.Name = 'Part'
local o5 = Instance.new('Part', workspace)
o5.Name = 'Part'
local o6 = Instance.new('UnionOperation', workspace)
o6.Name = 'Union'
local index = function(object, key)
    return object[key]
end
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.

https://devforum.roblox.com/t/getting-property-of-object/499382/11?u=8lx3

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

FIXED
i added tostring() so it could work

1 Like