I’m trying to make a simple datastore script but some problems occurred.
I keep getting this error
'DataStore request was added to a queue. If the request queue fills, further requests will be dropped. Try sending fewer requests. ’
which is extremely annoying. I tried wrapping the datastore script in a pcall, I tried adding waits in between the Datastore1:SetAsync bit, but no, nothing works.
Here’s what the script looks like in the explorer:
The script in the blue box
local Datastore = game:GetService("DataStoreService")
local Datakey = 640725830
local Datastore1 = Datastore:GetDataStore(Datakey)
game.Players.PlayerAdded:Connect(function(plr)
for _, folder in pairs(script.Datastores:GetDescendants()) do
if folder:IsA('Folder') then
local v = folder:Clone()
v.Parent = plr
for _, value in ipairs(v:GetDescendants()) do
if value.ClassName:match('Value') then
wait()
value.Value = Datastore1:GetAsync(plr.UserId,value) or 0
Datastore1:SetAsync(plr.UserId, value.Value)
end
end
end
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
for _, folder in pairs(plr:GetDescendants()) do
if folder:IsA('Folder') then
for _, value in ipairs(folder:GetDescendants()) do
if value.ClassName:match('Value') then
wait(0.1)
value.Value = Datastore1:SetAsync(plr.UserId,value.Value) or 0
wait(0.1)
end
end
end
end
end)
Well you are indeed requesting a lot of saves, what I recommend you do instead is, loop through everything, put everything inside of a table, then simply save that table
This isn’t an error but a warning that you’re sending too many datastore requests for the same key.
You need to find a way to use a different datastore key or reduce how many you’re sending by saving a table.
FYI: Instead of
if value.ClassName:match('Value') then
You can do
if value:IsA("ValueBase") then
Since the ValueBase group contains every type of Value.
Alright, here’s my new script (still gives the warning so please help)
local PlayerData = {}
local Datastore = game:GetService("DataStoreService")
local DataPoints = 0
local Datakey1 = 640725830
local Datastore1 = Datastore:GetDataStore(Datakey1)
game.Players.PlayerAdded:Connect(function(plr)
for _, folder in pairs(script.Datastores:GetDescendants()) do
if folder:IsA('Folder') then
local v = folder:Clone()
v.Parent = plr
for _, value in ipairs(v:GetDescendants()) do
if value.ClassName:match('Value') then
value.Value = Datastore1:GetAsync(plr.UserId,value) or 0
DataPoints = DataPoints + 1
table.insert(PlayerData,DataPoints,(Datastore1:GetAsync(plr.UserId,value.Value) or 0))
Datastore1:SetAsync(plr.UserId, PlayerData)
end
end
end
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
Datastore1:SetAsync(plr.UserId,PlayerData)
end)
for _, value in ipairs(v:GetDescendants()) do
if value.ClassName:match('Value') then
value.Value = Datastore1:GetAsync(plr.UserId,value) or 0
DataPoints = DataPoints + 1
table.insert(PlayerData,DataPoints,(Datastore1:GetAsync(plr.UserId,value.Value) or 0))
end
end
Datastore1:SetAsync(plr.UserId, PlayerData)
Instead of saving all values seperately you can better add them to a table and save the table only then you shouldnt have the problem
local PlayerData = {}
local Datastore = game:GetService("DataStoreService")
local Datakey1 = 640725830
local Datastore1 = Datastore:GetDataStore(Datakey1)
game.Players.PlayerAdded:Connect(function(plr)
for _, folder in pairs(script.Datastores:GetDescendants()) do
if folder:IsA('Folder') then
local v = folder:Clone()
v.Parent = plr
PlayerData[plr] = {}
for _, value in ipairs(v:GetDescendants()) do
if value.ClassName:match('Value') then
value.Value = Datastore1:GetAsync(plr.UserId,value.Name) or 0
PlayerData[plr][value.Name] = value.Value
value.Changed:Connect(function()
PlayerData[plr][value.Name] = value.Value
end)
end
end
Datastore1:SetAsync(plr.UserId, PlayerData[plr])
end
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
Datastore1:SetAsync(plr.UserId,PlayerData[plr])
PlayerData[plr] = nil
end)
This works fine for me it changes the value when you change it Example: Player.Boosters.Boost1 = 100 then you rejoin then it will set the boost1 to 100 here is the code and the issue about the datastore queue has been fixed too! enjoy!
local PlayerData = {}
local Datastore = game:GetService("DataStoreService")
local Datakey1 = 640725830
local Datastore1 = Datastore:GetDataStore(Datakey1)
game.Players.PlayerAdded:Connect(function(plr)
for _, folder in pairs(script.Datastores:GetDescendants()) do
if folder:IsA('Folder') then
local Header = folder:Clone()
Header.Parent = plr
PlayerData[plr] = {}
local Data = Datastore1:GetAsync(plr.UserId)
for _, value in pairs(Header:GetDescendants()) do
if value.ClassName:match('Value') then
value.Value = Data and Data[value.Name] or 0
PlayerData[plr][value.Name] = value.Value
value.Changed:Connect(function()
PlayerData[plr][value.Name] = value.Value
end)
end
end
--Datastore1:SetAsync(plr.UserId,PlayerData[plr])
end
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
Datastore1:SetAsync(plr.UserId,PlayerData[plr])
PlayerData[plr] = nil
end)
It always worked for me tho it works fine for values and never had any problem with it and nobody ever complained about data loss so xd but you can be right not sure tho I used changed already for like 5 years
Yeah guess it depends what people like to use tho if changed was really bad than roblox had removed it but you’re welcome feel free to change whatever you want if you need more help just let me know
OOOOOOOHHH, GetPropertyChangedSignal() only fires when a property is changed! It was underneath our noses the whole time . Thank you for helping me with my datastore script! I can’t believe how naive I just was! (does naive work in this context?)
It is fine I am glad I could help I wish you good luck with your project I only used GetPropertyChangedSignal for like example knowing if the visible property is changed of an UI. So good luck on your development journery
Use Changed for ValueObjects, not GetPropertyChangedSignal. Changed for ValueObjects is specially designed to fire when only the value changes and it is called with the new value as a parameter. GetPropertyChangedSignal is for other instances when needing granular change check control. It is also slightly slower because it is a callback, not a direct member of the instance.