DefeatedPurpose

Map loader

Dec 30th, 2020 (edited)
1,314
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.50 KB | None | 0 0
  1. LoadMap = function(Objects, Lighting_Info)
  2.     local Objs = {}
  3.     for i,v in next, Objects do
  4.         game:GetService("RunService").Heartbeat:Wait()
  5.         if v.className then
  6.             local Inst = Instance.new(v.className:sub(1, #v.className - 1))
  7.             table.insert(Objs, Inst)
  8.             for a, b in pairs(v) do
  9.                 local x, y = pcall(function()
  10.                     Inst[a] = type(b) == "string" and b:sub(1, #b - 1) or b
  11.                 end)
  12.                 if not x then
  13.                     if y:match("(Instance expected, got string)") then
  14.                         spawn(function()
  15.                             local Obj
  16.                             pcall(function()
  17.                                 Obj = loadstring("return "..b:sub(1, #b - 1))()
  18.                             end)
  19.                             if not Obj then
  20.                                 repeat
  21.                                     wait()
  22.                                     pcall(function()
  23.                                         Obj = loadstring("return "..b:sub(1, #b - 1))()
  24.                                     end)
  25.                                 until Obj
  26.                             end
  27.                             Inst[a] = Obj
  28.                         end)
  29.                     end
  30.                 end
  31.             end
  32.             spawn(function()
  33.                 local Obj
  34.                 pcall(function()
  35.                     Obj = loadstring("return "..v.Parent:sub(1, #v.Parent - 1))()
  36.                 end)
  37.                 if not Obj then
  38.                     repeat
  39.                         wait()
  40.                         pcall(function()
  41.                             Obj = loadstring("return "..v.Parent:sub(1, #v.Parent - 1))()
  42.                         end)
  43.                     until Obj
  44.                 end
  45.                 Inst.Parent = Obj
  46.             end)
  47.         end
  48.     end
  49.     for i, v in next, Objs do
  50.         if v:IsA("Seat") and v:FindFirstChild("SeatWeld") then
  51.             v["SeatWeld"]:Destroy()
  52.         end
  53.         v.Name = v.Name:sub(1, #v.Name - 13)
  54.     end
  55.     for i,v in next, Lighting_Info do
  56.         game:GetService("Lighting")[i] = type(v) == "string" and v:sub(1, #v -1) or v
  57.     end
  58. end
  59. LoadMap(Map, Lighting)
Add Comment
Please, Sign In to add comment