Skip to content

Instantly share code, notes, and snippets.

@Validark
Created March 13, 2017 02:09
Show Gist options
  • Save Validark/7ab8c708937b36c50efbbc2c79799166 to your computer and use it in GitHub Desktop.
Save Validark/7ab8c708937b36c50efbbc2c79799166 to your computer and use it in GitHub Desktop.
-- I found this in my old files.
-- It MANUALLY converts the data I wanted into JSON format.
-- I knew about JSONDecode but not JSONEncode
local Profilez=game.Workspace.Profiles
local StringToChange=game.Workspace.StringVal
function ValueIsInTable(d,TableOfObjects)
for a,r in pairs(TableOfObjects) do
if d==r then
return true
end
end
return false
end
function Finder(NumberOfTimesUsed,TableOfObjects)
for a,v in pairs(Profilez:GetChildren()) do
for c,d in pairs(v:GetChildren()) do
if d.NumberOfTimesUsed.Value==NumberOfTimesUsed and ValueIsInTable(d,TableOfObjects)==false then
return d
end
end
end
end
function Encode()
local NumOfTimesUsedTable={}
for a,v in pairs(Profilez:GetChildren()) do
for c,d in pairs(v:GetChildren()) do
table.insert(NumOfTimesUsedTable,d.NumberOfTimesUsed.Value)
end
end
table.sort(NumOfTimesUsedTable,function(a, b) return a > b end)
local TableOfObjects={}
for i=1,#NumOfTimesUsedTable do
--print(NumOfTimesUsedTable[i])
table.insert(TableOfObjects,Finder(NumOfTimesUsedTable[i],TableOfObjects))
end
local EncodedStuff="{"
for b=1,#TableOfObjects do
--print(tostring(TableOfObjects[b])..": "..TableOfObjects[b].NumberOfTimesUsed.Value)
if b==#TableOfObjects then --if last value
EncodedStuff=EncodedStuff..[["Name]]..b..[[":"]]..tostring(TableOfObjects[b])..[[","PosXCor]]..b..[[":]]..TableOfObjects[b].MapPosition.Position.X.Offset..[[,"PosYCor]]..b..[[":]]..TableOfObjects[b].MapPosition.Position.Y.Offset..[[,"Info]]..b..[[":"]]..TableOfObjects[b].Info.Text..[[","NumOfTimesChanged]]..b..[[":]]..TableOfObjects[b].NumberOfTimesUsed.Value
else
EncodedStuff=EncodedStuff..[["Name]]..b..[[":"]]..tostring(TableOfObjects[b])..[[","PosXCor]]..b..[[":]]..TableOfObjects[b].MapPosition.Position.X.Offset..[[,"PosYCor]]..b..[[":]]..TableOfObjects[b].MapPosition.Position.Y.Offset..[[,"Info]]..b..[[":"]]..TableOfObjects[b].Info.Text..[[","NumOfTimesChanged]]..b..[[":]]..TableOfObjects[b].NumberOfTimesUsed.Value..[[,]]
end
end
EncodedStuff=EncodedStuff.."}"
--[[for asd=1,12 do
print (game.HttpService:JSONDecode(EncodedStuff)["NumOfTimesChanged"..tostring(asd)])
wait(.1)
end
]]
return EncodedStuff
end
StringToChange.Value=Encode()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment