local DSS = game:GetService("DataStoreService")
local materialDS = DSS:GetDataStore("PlayerMaterials")
game.Players.PlayerAdded:Connect(function(player)
local materialFolder = Instance.new("Folder",player)
materialFolder.Name = "materialFolder"
local wood = Instance.new("IntValue",materialFolder)
wood.Value = 0
wood.Name = "wood"
local iron = Instance.new("IntValue",materialFolder)
iron.Value = 0
iron.Name = "iron"
local rock = Instance.new("IntValue",materialFolder)
rock.Value = 0
rock.Name = "rock"
local steel = Instance.new("IntValue",materialFolder)
steel.Value = 0
steel.Name = "steel"
local playerId = player.userId
local suc,err
repeat
suc,err = pcall(function()
return materialDS:GetAsync(playerId)
end)
wait()
until suc
wood.Value = err and err["Wood"] or 0
steel.Value = err and err["Canes"] or 0
rock.Value = err and err["Rock"] or 0
iron.Value = err and err["Iron"] or 0
end)
game.Players.PlayerRemoving:Connect(function(player)
local playerId = player.userId
local statsTable = {
["Wood"]=player.materialFolder.wood.Value,
["Steel"]=player.materialFolder.steel.Value,
["Rock"] = player.materialFolder.rock.Value,
["Iron"]=player.materialFolder.steel.Value
}
local success,err = pcall(function()
materialDS:SetAsync(playerId,statsTable)
end)
if success then
print("data")
else
print("failed")
end
end)
game:BindToClose(function()
local players = game.Players:GetPlayers()
for i,player in pairs(players) do
local playerId = player.userId
local statsTable = {
["Wood"]=player.materialFolder.wood.Value,
["Steel"]=player.materialFolder.steel.Value,
["Rock"] = player.materialFolder.rock.Value,
["Iron"]=player.materialFolder.steel.Value
}
local success,err = pcall(function()
materialDS:SetAsync(playerId,statsTable)
end)
if success then
print("data saved")
else
print("failed")
end
end
end)
but this warnings comes up:
DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key = 247406010
Hello,
I’m not sure if it changes really anything, but in your script everytime you want to get a User ID from a Player Instance, you are using player.userId with lowercase u, I think you should be using player.UserId with uppercase U. If this player.userId is a nil then your pcall will keep returning error because you are trying to use nil as a key. That will lead in your script just infinitly trying to do the pcall and that will lead into the warning that you are making too much requests. I might be wrong, but this is the thing that I’m thinking is causing this problem.
Hey man, now when i test it by playing the game it saves properly. Before i was testing it in studio. Am i supposed to test datastores in game? it saves and loads correctly too but the warning still exists in studio
I believe you can test it in either environment – if you’re playing the game from the website, you can also open up the Developer Console by clicking F9 and swapping to the Server view to see the Output there, if needed.
From my understanding, so long as the error is not excessive (such as upwards of a dozen every few seconds, around the mark that loleris, a prominent developer within the community, mentioned here), I don’t believe it’s a massive issue.
I’m not sure what changes you made to your code after reading through the other threads, so I would suggest testing it in an environment with more individuals/testing in Studio with multiple player instances via the “Test” tab, to see if the adjustments provided sufficient optimizations.
i mean it works and it saves all data is just warning me like this again
DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key = 247406010
it saves data when i normally play the game but theres no way i can see if its warning me there since its when i leave that the warning appears
Is “API access in studio” (or whatever its called) enabled? If its not then success will never become true. I also suggest to add a max tries (after n failed tries just give up) and logging the error message
local data
local success, err = pcall(function()
data = materialDS:GetAsync(player.UserId)
end)
if success then
wood.Value = data[1]
steel.Value = data[2]
rock.Value = data[3]
iron.Value = data[4]
else
print("The player has no data!")
end
same warning , and the warning occurs when i leave so doesnt it have to do with saving?