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