I am making a HTTP datastore When i decoded the json it looked like this ? {...} The json i encoded originally looked like this
[2065716711,[100,[0,4.49,0]]]
Full datastore code
local HTTP = game:GetService("HttpService")
local host = "http://localhost:8079"
function savetable(id,new,c)-- id = userid, new = newbie or normie, c = char instance
wait(2)
local luadata = {
id,
{
c.Humanoid.Health,
{
c.Head.Position.X, c.Head.Position.Y, c.Head.Position.Z
}
}
}
return luadata
end
function loaddata(tab,c)
succ = pcall(function()
local jsondata = tab
print(jsondata)
local maindata = tab[2]
local X = maindata[2][1]
local Y = maindata[2][2]
local Z = maindata[2][3]
local health = maindata[1]
--load
c.Humanoid.Health = health
c.HumanoidRootPart.CFrame = CFrame.new(Vector3.new(X, Y, Z))
--end load
end)
return succ
end
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Wait()
wait(1)
usertag = plr.UserId
c = plr.Character
print(c)
local success,reason = pcall(function()
print(HTTP:GetAsync(host.."/"..tostring(usertag)..".json"))
end)
if success then
new = false
local tabel = HTTP:JSONDecode(HTTP:GetAsync(host.."/"..tostring(usertag)..".json"))
print(tabel)
succus = loaddata(tabel,c)
if not succus then
--:(
wait(3)
loaddata(tabel,c)
end
elseif not success then
new = true
local jsondata = HTTP:JSONEncode(savetable(usertag, new, c))
print(reason)
HTTP:PostAsync(host, jsondata)
end
end)
--[[while true do wait(12)
pcall(function()
local jsondata = HTTP:JSONEncode(savetable(usertag, new, c))
print(jsondata)
HTTP:PostAsync(host, jsondata)
end)
end]]
The server side code is not related to lua, but is used for storing the files on my directory.
