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

How to create a Data Store that saves all leaderstats instead of one?

Currently this is the script I have

local DSService = game:GetService('DataStoreService'):GetDataStore('Currency')
game.Players.PlayerAdded:connect(function(plr)
	--[[ Stat1 ]]--
	local uniquekey = 'id-'..plr.userId
	local leaderstats = Instance.new('IntValue', plr)
	local savevalue =  Instance.new('IntValue')
	leaderstats.Name = 'leaderstats'
	savevalue.Parent = leaderstats
	savevalue.Name = 'Tokens' -- Stat Name
	
	
	local GetSaved = DSService:GetAsync(uniquekey)
	if GetSaved then
		savevalue.Value = GetSaved[1]
	else
		local NumbersForSaving = {savevalue.Value}
		DSService:SetAsync(uniquekey, NumbersForSaving)
	end
end)

game.Players.PlayerRemoving:connect(function(plr)
local uniquekey = 'id-'..plr.userId
local Savetable = {plr.leaderstats.Tokens.Value} -- Stat Name
DSService:SetAsync(uniquekey, Savetable)	
	
	
end)

I know I can just copy and paste and edit the stat names but I have a ton of stats and It would be very time consuming. Please help me!

1 answer

✓ Accepted answer

Use a table, datastores can save tables. So for example:

local datastore = game:GetService("DataStoreService"):GetDataStore("TestStore")
local myTable = {
	"string",
	1,
	true,
	workspace.Part
}

local mykey = "key"

datastore:SetAsync(key, myTable)

No problem.

2 comments

0

Thank you

0

You're welcome :P

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