Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Can't Parse JSON error? Datastore

Asked by 5 years ago
Edited by User#24403 5 years ago

This is the code I'm currently working on

```lua local servertime = {

days = 31,

hours = 0,

seconds = 0

}

local ds = game:GetService("DataStoreService")

local livetime = ds:GetDataStore("ServerTime")

local hs = game.HttpService -- the http service

local timer = game.Workspace.Timer

local d = timer.Days

local h = timer.Hours

local s = timer.Seconds

local value = hs:JSONDecode(livetime)

if value == nil then

value = servertime

else

local encode = hs:JSONEncode(value)

livetime:SetAsync("---Key---", encode)

end

And this is the reference code I was given:

--[[reference code:

local table = {a = "0",b = "0"} -- The main table

local ds = game:GetService("DataStoreService") -- datastore service

local hs = game.HttpService -- the http service

local nds = ds:GetDataStore("test")

local value = hs:JSONDecode(nds)

if value == nil then -- if it the first time you start the game then you start with the main table

value = table

else

value.a = value.a + 1 --we want to add 1 to a every time

value.b = value.b + 2 --we want to add 2 to b every time

end

local encode = hs:JSONEncode(value)

hs:SetAsync("test",encode) -- may be it (encode,"test")

--]] ```

and I get this error: "Can't parse JSON"

0
On what line? DeceptiveCaster 3761 — 5y
0
Don't specify. But it's most likely one of the hs:JSONEncode ItsBankai 31 — 5y

Answer this question