Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

1 answer

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. :( ]

This discussion is preserved as it was. New answers, comments, and votes are closed.