Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local toolbar = plugin:CreateToolbar("Model to Lua")
- local selected = game:GetService("Selection")
- local history = game:GetService("ChangeHistoryService")
- local button = toolbar:CreateButton("Transform", "Transform a model to Lua code", "rbxassetid://6499100516")
- local version_ = "1.9"
- local ClassProperties do
- ClassProperties = {}
- local HttpService = game:GetService("HttpService")
- local Data = HttpService:JSONDecode(HttpService:GetAsync("https://anaminus.github.io/rbx/json/api/latest.json"))
- for i = 1, #Data do
- local Table = Data[i]
- local Type = Table.type
- if Type == "Class" then
- local ClassData = {}
- local Superclass = ClassProperties[Table.Superclass]
- if Superclass then
- for j = 1, #Superclass do
- ClassData[j] = Superclass[j]
- end
- end
- ClassProperties[Table.Name] = ClassData
- elseif Type == "Property" then
- if not next(Table.tags) then
- local Class = ClassProperties[Table.Class]
- local Property = Table.Name
- local Inserted
- for j = 1, #Class do
- if Property < Class[j] then -- Determine whether `Property` precedes `Class[j]` alphabetically
- Inserted = true
- table.insert(Class, j, Property)
- break
- end
- end
- if not Inserted then
- table.insert(Class, Property)
- end
- end
- elseif Type == "Function" then
- elseif Type == "YieldFunction" then
- elseif Type == "Event" then
- elseif Type == "Callback" then
- elseif Type == "Enum" then
- elseif Type == "EnumItem" then
- end
- end
- end
- function CopyToLua(sub)
- local all = sub:GetChildren()
- local list = {}
- local count = 0
- sub.Name = string.gsub(sub.Name,"[^%l%u_]+","")
- table.insert(list,1,sub)
- local function add(all)
- for i = 1,#all do
- print("adding variables /"..tostring(i).."/ things")
- count = count+1
- if count>25 then
- wait()
- end
- table.insert(list,#list+1,all[i])
- end
- for i = 1,#all do
- wait()
- print("adding sub-variable /"..tostring(i).."/ things")
- if #(all[i]:GetChildren())>0 then
- add(all[i]:GetChildren())
- end
- end
- end
- add(all)
- local line = ""
- local cCount = 0
- for i = 1,#list do
- print("making variables /"..tostring(i).."/ things")
- if list[i] then
- local name = list[i].Name
- for x = 1,#list do
- if list[i].Name==list[x].Name and list[i]~=list[x] then
- cCount = cCount+1
- print("renaming variable")
- name = name..tostring(cCount)
- list[i].Name = name
- break
- end
- name = string.gsub(name,"[^%l%u_]+","")
- list[i].Name = name
- end
- line = line..[[
- local ]]..name..[[ = Instance.new("]]..list[i].ClassName..[[")]]
- end
- end
- for i = 1,#list do
- wait()
- print("proccessing, /"..tostring(i).."/ things")
- if list[i]~=nil then
- local props = ClassProperties[list[i].ClassName]
- local values = {}
- for a = 1,#props do
- table.insert(values,a,list[i][props[a]])
- end
- if #props>0 then
- --line = line.." local "..list[i].Name..[[ = Instance.new("]]..list[i].ClassName..[[", ]]..list[i].Parent.Name..[[)]]
- for o = 1,#props do
- local thing = typeof(values[o])
- local value
- if #(tostring(values[o]))<1 and props[o] ~= "LinkedSource" then
- if type(values[o]) == "string" then
- value = [[" "]]
- else
- if type(values[o])=="number" then
- value = "0"
- else
- value = "nil"
- end
- end
- else
- if thing == "Vector3" then
- print("vector")
- value = "Vector3.new("..tostring(values[o])..")"
- else
- if thing == "Udim2" then
- print("ud1m2")
- value = "Udim2.new("..tostring(values[o])..")"
- else
- if thing == "Color3" then
- print("color3")
- value = "Color3.new("..tostring(values[o])..")"
- else
- if thing == "BrickColor" then
- print("brickColor")
- value = [[BrickColor.new("]]..tostring(values[o])..[[")]]
- else
- if thing == "CFrame" then
- print("cframe matrix")
- value = "CFrame.new("..tostring(values[o].Position)..")*CFrame.Angles("..tostring(values[o].LookVector.Unit)..")"
- else
- if props[o]=="Name" then
- print("name")
- value = [["]]..tostring(values[o])..[["]]
- else
- if string.lower(string.sub(tostring(props[o]),#tostring(props[o])-1,#tostring(props[o])))=="id" or string.lower(props[o]) == "texture" then
- print("texture")
- value = [["]]..tostring(values[o])..[["]]
- else
- --check for rbxassetid://
- if string.lower(string.sub(tostring(values[o]),1,10))=="rbxassetid" then
- print("asset link")
- value = [["]]..tostring(values[o])..[["]]
- else
- if tostring(values[o]) == "inf" then
- print("infinite value")
- value = "math.huge"
- else
- --check for 'value'
- if string.sub(tostring(props[o]),#tostring(props[o])-5,#tostring(props[o]))=="Value" and type(values[o])=="string" then
- print("string value")
- value = [["]]..tostring(values[o])..[["]]
- else
- if string.sub(tostring(props[o]),#tostring(props[o])-7,#tostring(props[o]))=="Surface" then
- if tostring(values[o])=="nil" then
- print("surface texture")
- value = "Enum.SurfaceType.Smooth"
- end
- else
- if props[o] == "CustomPhysicalProperties" then
- print("physical properties")
- value = "PhysicalProperties.new("..tostring(values[o])..")"
- else
- if props[o] == "LinkedSource" then
- value = list[i].Source
- else
- value = tostring(values[o])
- end
- end
- end
- end
- end
- end
- --lol so many ends
- end
- end
- end
- end
- end
- end
- end
- end
- if tostring(props[o])=="LinkedSource" then
- warn("Setting script source")
- line = line..[[
- ]]..list[i].Name..".Source = [["..tostring(value).."]]"
- else
- if tostring(props[o])~="CustomPhysicalProperties" then
- line = line..[[
- ]]..list[i].Name.."."..props[o].." = "..tostring(value)
- end
- end
- end
- end
- end
- end
- local newCode = Instance.new("Script")
- newCode.Name = sub.Name.." Maker"
- newCode.Parent = workspace
- newCode.Disabled = false
- wait()
- local save = ""
- local worked,msg = pcall(function()
- for i = 1,4 do
- print("Inserting string "..tostring(i))
- wait(0.25)
- local ans = #line/4
- local spot = ((i-1)*ans)+1
- newCode.Source = newCode.Source..string.sub(line,spot,spot+(ans-1))
- save = newCode.Source..string.sub(line,spot,spot+(ans-1))
- end
- end)
- if worked == false then
- warn("Error at "..tostring(math.floor(tick())).." : "..msg..", attempted to make backup save.")
- return save, newCode
- end
- end
- function Clicked()
- local selection = selected:Get()
- if #selection==1 then
- warn("Starting Conversion "..version_.."...")
- wait(2)
- local save,code
- local worked, msg = pcall(function()
- save,code = CopyToLua(selection[1])
- end)
- if worked == false then
- warn("Error at "..tostring(math.floor(tick())).." : "..msg)
- pcall(function()
- if save and code then
- code.Parent = workspace
- code.Source = save
- code.Name = "Backup save: "..code.Name
- end
- end)
- end
- end
- end
- button.Click:Connect(Clicked)
Advertisement
Add Comment
Please, Sign In to add comment