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

can someone explain a simple explanation on how to use datastores?

Asked by
worklok -24
5 years ago

I am new to datastores, I don't know what to do. anyone have an explanation on how it works?thanks

0
thank you,ill check it out worklok -24 — 5y

1 answer

Log in to vote
0
Answered by
Nabfam 20
5 years ago

I understand I may be late to the party, but here:

local ds = game:GetService("DataStoreService") -- idk what this does but somehow its important
local data = ds:GetDataStore("VBucks") -- ditto ^

local json = game:GetService("HttpService") -- I think this might be useful in like 2034.

function loadData (key, tries, err) -- important stuff right here
    if not tries then
        tries = 1 -- if this is the first time it runs then do something
    end
    if tries > 3 then
        return err -- if it has tried this a lot then exit program
    end
    local g
    local s,m = pcall(function () -- error handle thingy
        g = data:GetAsync(key)
    end)
    if s and g then -- if success, give the person the data
        return http:JSONDecode(g)
    else
        table.insert(err,1,m) -- if error, add error to list and try again
        loadData(key,tries,err)
    end
end

[INCOMPLETE, WILL EDIT SOON. Sorry. :( ]

Ad

Answer this question