Help with datastore and https

local usid = "GLOBAL";
local ArrestData = game:GetService("DataStoreService"):GetDataStore("awdawdawdyesyesyesarrestlogs");
local https = game:GetService("HttpService")
local ltaa = {}
_G["ArrestLogs"] = {}

function savelogs()

	local save = https:JSONEncode(_G["ArrestLogs"])
	ArrestData:SetAsync(usid, save)
end

do
	local decode = https:JSONDecode(ArrestData:GetAsync(usid))
_G["ArrestLogs"] = decode
end

At line 16 it gives and error saying Argument 1 missing or nil, there’s no arrest logs yet, might be that?

It could be that ArrestLogs isn’t properly defined. Is it supposed to be inside a dictionary?

You don’t need to encode and decode tables with Datastores. They do that automatically.

When your GetAsync returns nil, you should set ArrestLogs to a default value, i.e. {}.

So for example,

do
    local logs = ArrestData:GetAsync(usid)
    if logs then
        _G["ArrestLogs"] = logs
    else
        _G["ArrestLogs"] = {}
    end
end
1 Like