I have made a data saving script which currently saves 4 values. Everytime it saves, I mean it works, but it says, DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key = Coins_182729712
So my question is, even though the data properly saves, is it bad to save so many values? Is it bad to leave it how it is?
Here is the script:
local dataStoreService = game:GetService("DataStoreService")
local myDataStore = dataStoreService:GetDataStore("myDataStore")
game.Players.PlayerAdded:Connect(function(player)
local stamina = Instance.new("IntValue")
stamina.Name = "Stamina"
stamina.Value = 100
stamina.Parent = player
local isSprinting = Instance.new("BoolValue")
isSprinting.Name = "IsSprinting"
isSprinting.Parent = player
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local cash = Instance.new("IntValue")
cash.Name = "Coins"
cash.Parent = leaderstats
local level = Instance.new("IntValue")
level.Name = "Level"
level.Parent = leaderstats
local experience = Instance.new("IntValue")
experience.Name = "Experience"
experience.Parent = player
local neededXP = Instance.new("IntValue")
neededXP.Name = "NeededXP"
neededXP.Parent = player
local coinsKey = "Coins_"..player.UserId
local levelKey = "Level_"..player.UserId
local XPKey = "XP_"..player.UserId
local XPNeededKey = "XPNeeded_"..player.UserId
local coinsData
local levelData
local experienceData
local neededXPData
local success, errormessage = pcall(function()
coinsData = myDataStore:GetAsync(coinsKey)
levelData = myDataStore:GetAsync(levelKey)
experienceData = myDataStore:GetAsync(XPKey)
neededXPData = myDataStore:GetAsync(XPNeededKey)
end)
if success then
level.Value = levelData
cash.Value = coinsData
experience.Value = experienceData
neededXP.Value = neededXPData
else
warn(errormessage)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local coinsKey = "Coins_"..player.UserId
local levelKey = "Level_"..player.UserId
local XPKey = "XP_"..player.UserId
local XPNeededKey = "XPNeeded_"..player.UserId
local coinsData = player.leaderstats.Coins.Value
local levelData = player.leaderstats.Level.Value
local XPData = player.Experience.Value
local XPNeededData = player.NeededXP.Value
local success, errormessage = pcall(function()
myDataStore:SetAsync(coinsKey, coinsData)
myDataStore:SetAsync(levelKey, levelData)
myDataStore:SetAsync(XPKey, XPData)
myDataStore:SetAsync(XPNeededKey, XPNeededData)
end)
if success then
warn("Data was saved!")
else
warn(errormessage)
end
end)
game:BindToClose(function()
for _, player in pairs(game.Players:GetPlayers()) do
local coinsKey = "Coins_"..player.UserId
local levelKey = "Level_"..player.UserId
local XPKey = "XP_"..player.UserId
local XPNeededKey = "XPNeeded_"..player.UserId
local coinsData = player.leaderstats.Coins.Value
local levelData = player.leaderstats.Level.Value
local XPData = player.Experience.Value
local XPNeededData = player.NeededXP.Value
local success, errormessage = pcall(function()
myDataStore:SetAsync(coinsKey, coinsData)
myDataStore:SetAsync(levelKey, levelData)
myDataStore:SetAsync(XPKey, XPData)
myDataStore:SetAsync(XPNeededKey, XPNeededData)
end)
if success then
warn("Data was saved!")
else
warn(errormessage)
end
end
end)
Is there a way to save the values as one value?