This one I was trying to save multiple values in one, but its not working. I have also tried using it for one, it gave no errors but didnt work. Does anyone know one that will work or can fix this one? And it also says im giving the datastore to many requests.
local DSService = game:GetService('DataStoreService'):GetDataStore('Protectiveses')
game.Players.PlayerAdded:connect(function(plr)
--Define varibles
local uniquekey= 'id'..plr.userId
local leaderstats = Instance.new('IntValue',plr)
local savevalue = Instance.new('IntValue')
local savevalue2 = Instance.new('IntValue')
leaderstats.Name = 'leaderstats'
savevalue.Parent = leaderstats
savevalue.Name = 'Money'
savevalue2.Parent = leaderstats
savevalue2.Name = 'Level'
savevalue2.Value = 1
-- GetAsync
local GetSaved = DSService:GetAsync(uniquekey)
local GetSaved2 = DSService:GetAsync(uniquekey)
if GetSaved then
savevalue.Value = GetSaved[1]
savevalue2.Value = GetSaved2[1]
else
local NumbersForSaving = {savevalue.Value}
DSService:SetAsync(uniquekey,NumbersForSaving)
local NumbersForSaving2 = {savevalue2.Value}
DSService:SetAsync(uniquekey,NumbersForSaving2)
game.ServerStorage.Give.Event:Connect(function(Amount)
savevalue.Value = savevalue.Value + Amount
game.ServerStorage.Give.Event:Connect(function(Amount)
savevalue2.Value = savevalue2.Value + Amount
end)
end)
end
end)
game.Players.PlayerRemoving:connect(function(plr)
local uniquekey = 'id-'..plr.userId
local Savetable = {plr.leaderstats.Money.Value}
DSService:SetAsync(uniquekey, Savetable)
local uniquekey = 'id-'..plr.userId
local Savetable = {plr.leaderstats.Level.Value}
DSService:SetAsync(uniquekey, Savetable)
end)

2 comments
My answer will work
Stolen from alvinbloxx: https://www.youtube.com/watch?v=tOOS9lMIYes + only requesting a fix