local DSService = game:GetService('DataStoreService'):GetDataStore('Data1')
game.Players.PlayerAdded:connect(function(plr)
local uniquekey = 'id-'..plr.userId
local leaderstats = Instance.new('IntValue', plr)
local savevalue = Instance.new('IntValue')
leaderstats.Name = 'leaderstats'
savevalue.Parent = leaderstats
savevalue.Name = 'Smackouts'
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.Smackouts.Value}
DSService:SetAsync(uniquekey, Savetable)
end)
I’m trying to save 2 leaderstats, one for kills and one for money. Is that possible? I have one script for kills, one script for money and one script for saving kills. I’ve tried to change it many times but it only fails.
First off, only use a few keys for saving data. DataStores are pretty mediocre and often can be finicky when saving numerous keys. Save everything under only a few universal keys.
And yes, you can save tables with DataStores. Add your values to a table and then when the player rejoins with the table, reassign the values of the player with the table.