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!
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.