How can I reference a global table dynamically with a string?

Hi!

i am making a plugin and I need to serialize tables so that they can be used within scripts but i want to do that dynamically
example

-- the table i want to serialize dynamiclly
local data = {
	Part = {
		["Position"] = {50,50,50},
		["Color"] = {255,255,255}
	},
	Frame = {
		["Udmi2"] = {1,0,1,0},
		["BackgroundColor3"] = {255,255,255}
	}
}

--serializing the table
for _, instanceName in data do
	for property, value in instanceName do
		local ins = Instance.new(instanceName) -- Instance.new is used to extract the properties type
		local propertyType = typeof(ins[property])
		--I need help here
		data[instanceName][property] = propertyType.new(table.unpack(value)) -- this isnot correct and i need help here
	end
end

now I can make a table with the existing data types but that is time consuming, and I don’t want to update the plugin if Roblox added a new data type

found out how to do it using loadstring()

local str = "Vector3"
local f = loadstring(`return {str}.new(5,5,5)`)

print(f())
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.