Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

Can't Parse JSON error? Datastore

Asked by 2 months ago
Edited by incapaxx 2 months 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? RobloxWhizYT 2026 — 2mo
0
Don't specify. But it's most likely one of the hs:JSONEncode ItsBankai 29 — 2mo

Answer this question