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

Best way for data saves?

So using data stores is it better to keep a long list and put it in a single datastore or get multiple datastores for stats.

1 answer

It depends if you're willing to decode it or not (decoding is kinda hard, with things like string patterns). I believe you can save tables, if that helps. Here's an example:

local ds = game:GetService("DataStoreService"):GetDataStore("PlayerData")

game.Players.PlayerAdded:connect(function(p)
	local data
	local key = "user_" ..p.UserId
	local success = pcall(function() data = ds:GetAsync("PlayerId") end)
	if not success then -- checks to see if player is new
		data = {["KOs"] = 0, ["WOs"] = 0}
	end
	setLeaderstatsToData(data) -- cause I can't be bothered writing a leaderstats script, and it'snot relevant
end

game.Players.PlayerRemoving:connect(function(p)
	local key = "user_" ..p.UserId
	local data = setDataToLeaderstats(p.leaderstats)
	if not data then -- sees if the data exist
		return
	end
	ds:SetAsync(key,data) -- or UpdateAsync()
end

1 comment

0

thanks

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