Im trying to make a plugin that turns the object you have selected into lua code, everything is working as intended but when i try to convert a larger model it just prints this error
“Unable to assign property Source. ProtectedString expected, got string”
function fixString(str)
return str:gsub("[%p%c%s]","")
end
function convert()
local model = selection:Get()
if #model > 1 then warn("Please select one model at a time.") return else model = model[1] end
local Script = Instance.new("Script",model.Parent)
local instanceCount = 0
local fixedName = fixString(model.Name)
ch:SetWaypoint("Added new script")
local convertedProperties = ConvertInstance(model,instanceCount)
local Source = "--"..model.Name.."--\n\nlocal "..fixedName.."_"..instanceCount.." = Instance.new(\""..model.ClassName.."\")"
for i,v in pairs(convertedProperties) do
Source = Source.."\n"..fixedName.."_"..instanceCount.."."..tostring(v)
end
instanceCount += 1
if #model:GetDescendants() > 0 then
for i,dec in pairs(model:GetDescendants()) do
if props[dec.ClassName] then
fixedName = fixString(dec.Name)
Source = Source.."\n\n--"..dec.Name.."--\n\nlocal "..fixedName.."_"..instanceCount.." = Instance.new(\""..dec.ClassName.."\")"
local convertedProperties = ConvertInstance(dec,instanceCount)
for i,c in pairs(convertedProperties) do
Source = Source.."\n"..fixedName.."_"..instanceCount.."."..tostring(c)
end
instanceCount += 1
end
end
end
table.clear(convertedInstances)
Script.Source = Source
Script.Name = model.Name.." to lua"
end
button.Click:Connect(convert)
I think the problem could be in there but if u need to know more just let me know
I’ve finally figured out the issue for those who are interested,
This apparently comes out when the length of the source > 199999
(which the message doesn’t imply at all)
If anybody needs code to make the source files and split the source here is some:
source = string.rep("e", 1025392)
print("Creating source file, source length " .. #source)
if #source < 200000 then
local sourcefile = Instance.new("Script", script)
sourcefile.Source = source
sourcefile.Name = "Source"
print("Source file created :", sourcefile)
else
print("Source is >= 200000 characters, resault will have to be split")
local sources = {}
local p = 1
local c = 1
repeat
local sourcefile = Instance.new("Script", script)
sourcefile.Source = source:sub(p,p+199998)
sourcefile.Name = "Source" .. c
table.insert(sources, sourcefile)
p += 199999
c += 1
until p > #source
print("Source files created :", table.unpack(sources))
end