Heres my code, I want to be able to save multiple values but it says 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

0

Put the part that saves in a loop, and make it look about every 10-20 seconds so it doesn't overload the DataStore.

0

But will it save?