How do I get every data type in game and their constructor easily?

  1. What do you want to achieve?
    Im working on a plugin that makes it so that objects get written into lua instantly.
    I have a list of instance properties and per property i want to initialize it through another script by changing the script’s source.

  2. What is the issue?
    There is currently no way, atleast that i know of that makes me able to check the data type and get its constructor(Vector3.new etc).

  3. What solutions have you tried so far?
    I know you can use typeof to check the type of a certain property, but manually writing every type that exists and their creation function is really tedious, As you can see I have tried that in the script below.

	for _, v in (game.Selection:Get()) do
		local instanceprops = info.getInstanceProperties(v.ClassName) -- gets all the writable properties a class type contains

		script.Source = script.Source .. '\n local ' .. v.Name .. ' = Instance.new("' .. v.ClassName .. '")'
		script.Source = script.Source .. '\n ' .. v.Name .. '.Name = '.. tostring(v.Name)
		script.Source = script.Source .. '\n ' .. v.Name .. '.Parent = '.. tostring(v.Parent)
		for _, p in instanceprops do
			if typeof(v[p]) == "number" then
				script.Source = script.Source .. '\n ' .. v.Name .. '.' .. p .. ' = ' .. tostring(v[p])
			elseif typeof(v[p]) == "string" then
				script.Source = script.Source .. '\n ' .. v.Name .. '.'.. p..' = "'..v[p]..'"'
			elseif typeof(v[p]) == "boolean" then
				script.Source = script.Source..'\n '..v.Name..'.'..p..' = '..tostring(v[p])
			elseif typeof(v[p]) == "Vector2" then
				script.Source = script.Source..'\n '..v.Name..'.'..p..' = '..'Vector2.new('..tostring(v[p])..')'
			end
		end
	end

I would really appreciate the help right now, because I intend to release this plugin for free to contribute to the community and make the writing of instances and their properties less time consuming. If someone has a list of all data types with their constructor, i wouldn’t mind writing it manually.

I think they only fall into a few methods. The base types like you have listed, number, string, and boolean. Instances; these would use Instance.new("my type"), and the Data Types like Vector3, Color3, and UDim that use mytype.new()

Try keeping an array of each type and programatically insert them

local DataTypes = {
"Vector2",
"Vector3",
"UDim",
"UDim2",
"Color3",
}
local InstanceTypes = {
"Part",
"Humanoid",
"BindableEvent"
}

for _, p in instanceprops do 
	if typeof(v[p]) == "number" then
		script.Source = script.Source .. '\n ' .. v.Name .. '.' .. p .. ' = ' .. tostring(v[p])
	elseif typeof(v[p]) == "string" then
		script.Source = script.Source .. '\n ' .. v.Name .. '.'.. p..' = "'..v[p]..'"'
	elseif typeof(v[p]) == "boolean" then
		script.Source = script.Source..'\n '..v.Name..'.'..p..' = '..tostring(v[p])
	elseif table.find(DataTypes, typeof(v[p])) then
		script.Source = script.Source..'\n '..v.Name..'.'..p..' = '.. typeof(v[p]) ..  '.new('..tostring(v[p])..')'
	elseif table.find(InstanceTypes, typeof(v[p])) then		
		script.Source = script.Source..'\n '..v.Name..'.'..p..' = '.. 'Instance.new("' .. typeof(v[p]) .. '")'
	end

Thank you for your response, I will look into this method. It would be easier if I could just find a list with every type that exists though.

Hello people, sorry for the bump. But I have found a list for anyone that needs it.
Apparently it was really easy to find, I’m just blind. Roblox Engine Data Types | Documentation - Roblox Creator Hub

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