local leveldata = game:GetService("DataStoreService"):GetDataStore("level") local EXPdata = game:GetService("DataStoreService"):GetDataStore("EXP") local xpLeveldata = game:GetService("DataStoreService"):GetDataStore("xpLevel") local Golddata = game:GetService("DataStoreService"):GetDataStore("Gold") function savedata(dataname, playerid, value) game:GetService("DataStoreService"):GetDataStore(dataname):SetAsync(playerid, value) end game.Players.PlayerAdded:connect(function(player) local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Parent = player local gold = Instance.new("IntValue") gold.Value = Golddata:GetAsync(tostring(player.userId)) gold.Name = "Gold" gold.Parent = leaderstats gold.Value = 500 local level = Instance.new("IntValue") level.Value = leveldata:GetAsync(tostring(player.userId)) or 1 level.Name = "Level" level.Parent = leaderstats level.Value = 1 local EXP = Instance.new("IntValue") EXP.Value = EXPdata:GetAsync(tostring(player.userId)) EXP.Parent = player EXP.Name = "Exp" local xpLevel = Instance.new("IntValue") xpLevel.Value = xpLeveldata:GetAsync(tostring(player.userId)) or 500 xpLevel.Value = 500 xpLevel.Name = 'ExpNeeded' xpLevel.Parent = player EXP.Changed:connect(function() if player:WaitForChild('Exp').Value >= player:WaitForChild('ExpNeeded').Value then level.Value = level.Value + 1 xpLevel.Value = xpLevel.Value + (xpLevel.Value/2) EXP.Value = 0 savedata('leveldata',player.userId,level.Value) savedata('EXPdata',player.userId,EXP.Value) savedata('xpLeveldata',player.userId,xpLevel.Value) savedata('Golddata',player.userId,gold.Value) end end) game.Players.PlayerRemoving:Connect(function(player) savedata('leveldata',player.userId,player.leaderstats.Level.Value) savedata('EXPdata',player.userId,player.EXP.Value) savedata('xpLeveldata',player.userId,player.ExpNeeded.Value) savedata('Golddata',player.userId,player.leaderstats.Gold.Value) end)
so this is my code in my leaderstats but every time i kill an enemy and get EXP it says "Request was throttled. Try sending fewer requests. Key = 306209.
I dont feel as if i am requesting that many for it to throttle?
You can check the specific limitations here. In particular, you might be killing enemies too fast, as there is a 6 second delay between same key writing. Beyond that however, saving every time you kill an enemy is generally bad practice, as it will quickly use up your limit and throttle your requests. I would suggest either only saving when the character leaves, or an automated save, or sectioning out save intervals in some other way. Additionally, it seems that your load/save is all being done at the same time, in which case you can actually condense your code to only save once and load one from a table that contains all of your player's data, rather than using separate keys for each player stat. For instance, you can create a table like such:
local playerData = {} playerData.Level = leaderstats.Level.Value playerData.Gold = leaderstats.Gold.Value
and so on, and simply save the table, which reduces the number of writes required by 4x. When loading from the data, you would then access the data with the same keys you wrote when creating the table.