You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
Data store need to work
What is the issue? Include screenshots / videos if possible! DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key = Player_665424657 - Studio
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
didnt found
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
--Services--
local Players = game:GetService("Players")
local DTS = game:GetService("DataStoreService")
------------------------------------------------
--Data--
local Data = DTS:GetDataStore("Test1")
--------------------------------------
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Clicks = Instance.new("IntValue")
Clicks.Name = "Clicks"
Clicks.Value = 50
Clicks.Parent = leaderstats
local playerUserId = "Player_"..player.UserId
local data
local success, errormsg = pcall(function()
data = Data:GetAsync(playerUserId)
end)
if success then
Clicks.Value = data
end
end)
local function saveData(player)
local playerUserId = "Player_"..player.UserId
local data = player.leaderstats.Clicks.Value
local success,errorMsg = pcall(function()
Data:SetAsync(playerUserId,data)
end)
if success then
print("Data Saved", player.Name)
else
warn(errorMsg)
end
end
game.Players.PlayerRemoving:Connect(function(player)
saveData(player)
end)
game:BindToClose(function()
for _, player in pairs(game.Players:GetPlayers()) do
saveData(player)
end
end)
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.
Maybe this happens because when the player leaves and if he is the last one, bindtoclose will be triggered immediately afterwards, saving the same id twice, that’s what I thought.
I would recommend instead of saving the clicks themselves, creating a table containing the player’s data such as clicks, etc. I think it’s more practical and I won’t need to create new data stores in the future
This isn’t saying it didn’t work … it’s just a warning because it had to wait for a moment. You could send two in a row and get this warning even though nothing failed.
I’m not all to sure about this but, I think I read someplace every player in the game has an amount of request queues. So for each player added that number goes up. You would have to hammer the requests to go over that.
This also seems to happen in the studio and not as much compiled. (the warning)
In a perfect world .. You should read the data once and wright the data once. When they start and when they leave. Once you have read the data use the program to deal with it. Not use the data calls constantly to deal with the data.
I do have a few programs that use a leaderboard that will update every 60 seconds. But that is on a different data store than the one I use for the player.
It looks like you’re keeping track of clicks here. I hope you’re not updating the datastore with every click. Keep track of that with a variable and just update when they leave …
--Services--
local Players = game:GetService("Players")
local DTS = game:GetService("DataStoreService")
------------------------------------------------
--Data--
local Data = DTS:GetDataStore("Test2")
--------------------------------------
local MyDatasCache = {}
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Clicks = Instance.new("IntValue")
Clicks.Name = "Clicks"
Clicks.Parent = leaderstats
local attempts = 0
local Sucess,Data
repeat
Sucess,Data = pcall(function() return DTS:GetAsync("User_"..player.UserId) end)
if Sucess then break end
attempts += 1
task.wait(1)
until attempts == 5
if Sucess then
MyDatasCache[player.UserId] = Data or {}
else
warn(Data)
player:Kick("Rejoin")
end
Clicks.Value = MyDatasCache[player.UserId]["Clicks"] or 50 -- DataSave or Base Value
Clicks:GetPropertyChangedSignal("Value"):Connect(function()
MyDatasCache[player.UserId]["Clicks"] = Clicks.Value
end)
end)
local function saveData(UserID)
local Player = game.Players:GetPlayerByUserId(UserID)
if not MyDatasCache[UserID] then return end
local MainDataCache = table.clone(MyDatasCache[UserID])
MyDatasCache[UserID] = nil
if MainDataCache then
local attempts = 0
local Sucess,Error
repeat
Sucess,Error = pcall(function() DTS:SetAsync("User_"..UserID,MainDataCache) end)
if Sucess then break end
attempts += 1
task.wait(1)
until attempts == 5
if not Sucess then warn(Error) end
end
end
game.Players.PlayerRemoving:Connect(function(player)
saveData(player.UserId)
end)
game:BindToClose(function()
for UserId,_ in pairs(MyDatasCache) do
saveData(UserId)
end
end)
--Services--
local Players = game:GetService("Players")
local DTS = game:GetService("DataStoreService")
------------------------------------------------
--Data--
local Data = DTS:GetDataStore("Test2")
--------------------------------------
local MyDatasCache = {}
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Clicks = Instance.new("IntValue")
Clicks.Name = "Clicks"
Clicks.Parent = leaderstats
local attempts = 0
local Sucess,Data
repeat
Sucess,Data = pcall(function() return Data:GetAsync("User_"..player.UserId) end)
if Sucess then break end
attempts += 1
wait(1)
until attempts == 5
if Sucess then
MyDatasCache[player.UserId] = Data or {}
else
warn(Data)
player:Kick("Rejoin")
end
Clicks.Value = MyDatasCache[player.UserId]["Clicks"] or 50 -- DataSave or Base Value
Clicks:GetPropertyChangedSignal("Value"):Connect(function()
MyDatasCache[player.UserId]["Clicks"] = Clicks.Value
end)
end)
local function saveData(UserID)
local Player = game.Players:GetPlayerByUserId(UserID)
if not MyDatasCache[UserID] then return end
local MainDataCache = table.clone(MyDatasCache[UserID])
MyDatasCache[UserID] = nil
if MainDataCache then
local attempts = 0
local Sucess,Error
repeat
Sucess,Error = pcall(function() Data:SetAsync("User_"..UserID,MainDataCache) end)
if Sucess then break end
attempts += 1
wait(1)
until attempts == 5
if not Sucess then warn(Error) end
end
end
game.Players.PlayerRemoving:Connect(function(player)
saveData(player.UserId)
end)
game:BindToClose(function()
for UserId,_ in pairs(MyDatasCache) do
saveData(UserId)
end
end)
--Services--
local Players = game:GetService("Players")
local DTS = game:GetService("DataStoreService")
------------------------------------------------
--Data--
local DataKey = DTS:GetDataStore("Test2")
--------------------------------------
local MyDatasCache = {}
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Clicks = Instance.new("IntValue")
Clicks.Name = "Clicks"
Clicks.Parent = leaderstats
local attempts = 0
local Sucess,Data
repeat
Sucess,Data = pcall(function() return DataKey:GetAsync("User_"..player.UserId) end)
if Sucess then break end
attempts += 1
wait(1)
until attempts == 5
if Sucess then
MyDatasCache[player.UserId] = Data or {}
else
warn(Data)
player:Kick("Rejoin")
end
Clicks.Value = MyDatasCache[player.UserId]["Clicks"] or 50 -- DataSave or Base Value
Clicks:GetPropertyChangedSignal("Value"):Connect(function()
MyDatasCache[player.UserId]["Clicks"] = Clicks.Value
end)
end)
local function saveData(UserID)
local Player = game.Players:GetPlayerByUserId(UserID)
if not MyDatasCache[UserID] then return end
local MainDataCache = table.clone(MyDatasCache[UserID])
MyDatasCache[UserID] = nil
if MainDataCache then
local attempts = 0
local Sucess,Error
repeat
Sucess,Error = pcall(function() DataKey:SetAsync("User_"..UserID,MainDataCache) end)
if Sucess then break end
attempts += 1
wait(1)
until attempts == 5
if not Sucess then warn(Error) end
end
end
game.Players.PlayerRemoving:Connect(function(player)
saveData(player.UserId)
end)
game:BindToClose(function()
for UserId,_ in pairs(MyDatasCache) do
saveData(UserId)
end
end)
--Services--
local Players = game:GetService("Players")
local DTS = game:GetService("DataStoreService")
------------------------------------------------
--Data--
local DataKey = DTS:GetDataStore("Test2")
--------------------------------------
local MyDatasCache = {}
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Clicks = Instance.new("IntValue")
Clicks.Name = "Clicks"
Clicks.Parent = leaderstats
local attempts = 0
local Sucess,Data
repeat
Sucess,Data = pcall(function() return DataKey:GetAsync("User_"..player.UserId) end)
if Sucess then break end
attempts += 1
wait(1)
until attempts == 5
if Sucess then
MyDatasCache[player.UserId] = Data or {}
else
warn(Data)
player:Kick("Rejoin")
end
Clicks.Value = MyDatasCache[player.UserId]["Clicks"] or 50 -- DataSave or Base Value
Clicks:GetPropertyChangedSignal("Value"):Connect(function()
MyDatasCache[player.UserId]["Clicks"] = Clicks.Value
end)
end)
local function saveData(UserID,RemoveTab)
if not MyDatasCache[UserID] then return end
local MainDataCache = table.clone(MyDatasCache[UserID])
if RemoveTab then
MyDatasCache[UserID] = nil
end
if MainDataCache then
local attempts = 0
local Sucess,Error
repeat
Sucess,Error = pcall(function() DataKey:SetAsync("User_"..UserID,MainDataCache) end)
if Sucess then break end
attempts += 1
wait(1)
until attempts == 5
if not Sucess then warn(Error) end
end
end
if game:GetService("RunService"):IsStudio() then
task.spawn(function()
while true do
task.wait(10)
for UserId,_ in pairs(MyDatasCache) do
saveData(UserId,false)
end
end
end)
end
game.Players.PlayerRemoving:Connect(function(player)
saveData(player.UserId,true)
end)
game:BindToClose(function()
for UserId,_ in pairs(MyDatasCache) do
saveData(UserId,true)
end
end)
Now when you are in Roblox Studio it will save every 10 seconds, if you are in the normal game it will save when you exit.