Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function serialize(x, doNotJSON)
- local s = {}
- if typeof(x) == "Instance" then
- s.____s = "Instance"
- s.x = {}
- for i,v in pairs(x:GetProperties()) do
- if i ~= "Parent" then
- s.x[i] = serialize(v)
- end
- end
- s.c = {}
- for _,v in pairs(x:GetChildren()) do
- table.insert(s.c, serialize(v))
- end
- elseif typeof(x) == "table" then
- s.____s = "table"
- local n = {}
- for i,v in pairs(x) do
- n[serialize(i)] = serialize(v)
- end
- s.x = n
- else
- s.____s = typeof(x)
- s.x = tostring(x)
- end
- return doNotJSON and s or game.HttpService:JSONEncode(s)
- end
- function unserialize(x)
- local s = x
- pcall(function()
- s = game.HttpService:JSONDecode(x) or s
- end)
- if s and typeof(s) == "table" and s.____s and s.x then
- if s.____s == "string" then
- return s.x
- elseif s.____s == "number" then
- return tonumber(s.x)
- elseif s.____s == "table" then
- local n = {}
- for _,v in pairs(s.x) do
- n[unserialize(_)] = unserialize(v)
- end
- return n
- elseif s.____s == "Instance" then
- local i
- pcall(function() i = Instance.new(unserialize(s.x.ClassName)) end)
- if i then
- for _,v in pairs(s.x) do
- pcall(function() i[_] = unserialize(v) end)
- end
- for _,v in pairs(s.c) do
- local c = unserialize(v)
- if c then
- c.Parent = i
- end
- end
- end
- return i
- elseif s.____s == "boolean" then
- return s.x == "true"
- elseif s.____s == "Enums" then
- return Enum
- elseif s.____s == "Enum" then
- return Enum[s.x]
- elseif s.____s == "EnumItem" then
- local x = string.split(s.x,".")
- return Enum[x[2]][x[3]]
- elseif s.____s == "BrickColor" then
- return BrickColor.new(s.x)
- elseif s.____s == "Ray" then
- local x = string.split(s.x, "},")
- return Ray.new(Vector3.new(unpack(string.split(x[1]:gsub(" ",""):gsub("{", ""):gsub("}", ""),","))), Vector3.new(unpack(string.split(x[2]:gsub(" ",""):gsub("{", ""):gsub("}", ""),","))))
- elseif s.____s == "Region3" then
- local x = string.split(s.x, ";")
- local pos = CFrame.new(unpack(string.split(x[1]:gsub(" ",""):gsub("{", ""):gsub("}", ""),","))).p
- local sz = Vector3.new(unpack(string.split(x[2]:gsub(" ",""):gsub("{", ""):gsub("}", ""),",")))
- local SizeOffset = sz/2
- local Point1 = pos - SizeOffset
- local Point2 = pos + SizeOffset
- return Region3.new(Point1, Point2)
- elseif s.____s == "Region3int16" then
- local x = string.split(s.x, ";")
- local a = CFrame.new(unpack(string.split(x[1]:gsub(" ",""):gsub("{", ""):gsub("}", ""),","))).p
- local pos = Vector3int16.new(a.x,a.y,a.z)
- local sz = Vector3int16.new(unpack(string.split(x[2]:gsub(" ",""):gsub("{", ""):gsub("}", ""),",")))
- local SizeOffset = sz/2
- local Point1 = pos - SizeOffset
- local Point2 = pos + SizeOffset
- return Region3int16.new(Point1, Point2)
- elseif s.____s == "UDim2" then
- return UDim2.new(unpack(string.split(s.x:gsub(" ",""):gsub("{", ""):gsub("}", ""),",")))
- elseif s.____s == "Region3int16" or s.____s == "Vector3int16" or s.____s == "Vector2int16" or s.____s == "Region3" or s.____s == "UDim" or s.____s == "Vector3" or s.____s == "Vector2" or s.____s == "CFrame" or s.____s == "Color3" then
- return getfenv()[s.____s].new(unpack(string.split(s.x:gsub(" ",""),",")))
- end
- elseif typeof(x) == "table" then
- local n = {}
- for _,v in pairs(x) do
- n[unserialize(_)] = unserialize(v)
- end
- return n
- end
- return x
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement