The titles a bit messy but I’ll explain
If I want the value of a parts BrickColor I just do Part.BrickColor, but when I use print
or tostring
it returns just the string of the BrickColor.
print(BrickColor.new('Really Red')) -- Really Red
But I want it so that it would output
'BrickColor.new("Really Red")' -- as a string
Now I could just format it simply by doing
if typeof(v) == 'BrickColor' then
return 'BrickColor.new('..tostring(v)..')'
end
But that would take a lot of effort so I wondered if there was an automated way to do this or even a built in way.
I’ll probably have to resort to my previous method for many different types but I’m sorta lazy and want a nice code instead of a bunch of elseif
s
My simple solution right now;
local function valueise(v)
local t = type(v)
if t == 'string' then
return tostring('"'..v..'"')
elseif t == 'number' or t == 'boolean' then
return tostring(v)
elseif t == 'vector3' then
return 'Vector3.new('..v..')'
else
local to = typeof(v)
if to == 'Instance' then
return 'game.'..v:GetFullName()
elseif to == 'BrickColor' then
return 'BrickColor.new('..valueise(tostring(v))..')'
elseif to == 'EnumItem' then
return tostring(v)
end
end
end