Hello. This is the second time in having issues with my datastore today. As the title explains, I get an error, saying that Datastore request was added to queue. I have no idea how to add a wait
local DataStore = game:GetService("DataStoreService")
local FlowerManger = DataStore:GetDataStore("flrs")
local ResetManager = DataStore:GetDataStore("resets")
local PlyrServ = game:GetService("Players")
game.Players.PlayerAdded:Connect(function(player)
local ls = Instance.new("Folder")
ls.Name = "leaderstats"
ls.Parent = player
local flrs = Instance.new("IntValue")
flrs.Name = "Flowers"
flrs.Value = 0
flrs.Parent = ls
local resets = Instance.new("IntValue")
resets.Name = "Resets"
resets.Value = 0
resets.Parent = ls
local data
local reset
local success,errormessage = pcall(function()
data = FlowerManger:GetAsync(player.UserId.."-Flowers")
end)
if success then
flrs.Value = data
print("Loaded In Data")
else
warn(errormessage)
print("Failed To Load Data")
end
local success3, errormessage3 = pcall(function()
reset = ResetManager:GetAsync(player.UserId.."-Resets")
end)
if success3 then
resets.Value = reset
print("Resets have been loaded in")
else
warn(errormessage3)
print("Resets have failed to load in")
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local success,errormessage = pcall(function()
FlowerManger:SetAsync(player.UserId.."-Flowers",player.leaderstats.Flowers.Value)
end)
if success then
print("Data Success")
else
print("Data Failed")
warn(errormessage)
end
local success1, errormessage2 = pcall(function()
ResetManager:SetAsync(player.UserId.."-Resets",player.leaderstats.Resets.Value)
end)
if success1 then
print("Reset Loaded Sucessfully")
else
print("Reset Failed To Load")
warn(errormessage2)
end
end)
The error seems to be coming from a different script as requests.Key in the error is not the same as any of the keys in this script, the keys in this script end in either -Flowers or -Resets.
You can read more on why this warning occurs and what the best practices are to prevent it here: Data Stores
Firstly, the link that you gave me has nothing explaining this error ( at least what I found ) Secondly, I dont have a script that has “requests” in it. Although, there are a lot of scripts that add to the values of -Resets and -Flowers. Thirdly, I still have no idea what to do with my script.
I don’t think it’s an issue if it happens only once. It basically says that your datastore has been queued to be updated, and it might take a while.
It’s weird it happens to error like this when the SetAsync is only connected when the player leaves. Maybe check if the same key is used anywhere else?
When you say " a while" how long is " a while"?
Btw, I am adding to Resets and Flowers in workspace. The scripts are in meshes or parts. (Parts being “resets”, “Flowers” being meshes)
By “a while” I mean like 10 seconds. I don’t quite understand how the flowers data works. Do you have a GetAsync for every single flower in your game? Otherwise I wouldn’t see why it should error.
First off, remove the part where the data saves every time the leaderstats values update.
Instead of that, make something like
game:GetService('Players').PlayerRemoving:Connect(function(player)
local SaveSuccess, SaveError = pcall(function()
YourDataStore:SetAsync(player.UserId.."YourKey", your_data_table)
end)
end)
or
local players = game:GetService("Players")
players.PlayerRemoving:Connect(function(plr)
local leaderstats = plr:WaitForChild("leaderstats")
local cash = leaderstats:WaitForChild("Cash")
repeat
local success, errormessage = pcall(function()
DataStore:SetAsync(plr.UserId, cash.Value)
end)
until success
end)
local DataStore = game:GetService("DataStoreService")
local FlowerManger = DataStore:GetDataStore("flrs")
local ResetManager = DataStore:GetDataStore("resets")
local PlyrServ = game:GetService("Players")
game.Players.PlayerAdded:Connect(function(player)
local ls = Instance.new("Folder")
ls.Name = "leaderstats"
ls.Parent = player
local flrs = Instance.new("IntValue")
flrs.Name = "Flowers"
flrs.Value = 0
flrs.Parent = ls
local resets = Instance.new("IntValue")
resets.Name = "Resets"
resets.Value = 0
resets.Parent = ls
local data
local reset
local success,errormessage = pcall(function()
data = FlowerManger:GetAsync(player.UserId.."-Flowers")
end)
if success then
flrs.Value = data
print("Loaded In Data")
else
warn(errormessage)
print("Failed To Load Data")
end
local success3, errormessage3 = pcall(function()
reset = ResetManager:GetAsync(player.UserId.."-Resets")
end)
if success3 then
resets.Value = reset
print("Resets have been loaded in")
else
warn(errormessage3)
print("Resets have failed to load in")
end
end)
PlyrServ.PlayerRemoving:Connect(function(plr)
local leaderstats = plr:WaitForChild("leaderstats")
local cash = leaderstats:WaitForChild("Flowers")
local resetva = leaderstats:WaitForChild("Resets")
repeat
local success, errormessage = pcall(function()
FlowerManger:SetAsync(plr.UserId, cash.Value)
ResetManager:SetAsync(plr.UserId, resetva.Value)
end)
until success
end)
local DataStore = game:GetService("DataStoreService")
local FlowerManger = DataStore:GetDataStore("flrs")
local ResetManager = DataStore:GetDataStore("resets")
local PlyrServ = game:GetService("Players")
game.Players.PlayerAdded:Connect(function(player)
local ls = Instance.new("Folder")
ls.Name = "leaderstats"
ls.Parent = player
local flrs = Instance.new("IntValue")
flrs.Name = "Flowers"
flrs.Value = 0
flrs.Parent = ls
local resets = Instance.new("IntValue")
resets.Name = "Resets"
resets.Value = 0
resets.Parent = ls
local data
local reset
local success,errormessage = pcall(function()
data = FlowerManger:GetAsync(player.UserId.."-Flowers")
end)
if success then
flrs.Value = data
print("Loaded In Data")
else
warn(errormessage)
print("Failed To Load Data")
end
local success3, errormessage3 = pcall(function()
reset = ResetManager:GetAsync(player.UserId.."-Resets")
end)
if success3 then
resets.Value = reset
print("Resets have been loaded in")
else
warn(errormessage3)
print("Resets have failed to load in")
end
end)
PlyrServ.PlayerRemoving:Connect(function(plr)
local leaderstats = plr:WaitForChild("leaderstats")
local cash = leaderstats:WaitForChild("Flowers")
local resetva = leaderstats:WaitForChild("Resets")
local success, errormessage = pcall(function()
FlowerManger:SetAsync(plr.UserId, cash.Value)
ResetManager:SetAsync(plr.UserId, resetva.Value)
end)
end)