And I read a lot about that, it seems that it happens because of the “6 seconds time” thing, but I’m mostly curious about the “If request queue fills, further requests will be dropped.” part. I don’t really understand what does that mean…?
Here’s some codes that overwrites this value:
And another one that I created when player equips the tool and I need to set their values back to original ones:
What it is trying to tell you is that if you continue trying to save data to the same key, at one point the queue that the save request tries to enter just won’t accept any more requests. In short, it won’t save your data. You should definitely fix this by saving data efficiently.
I don’t understand why you’re saving twice when the player leaves. Also, instead of creating a key for each value you’re trying to save, put everything inside of a table and save the table instead. Take a look at the following:
thanks! and im saving 2 datas because second script is a script for when player holds a tool that boosts these stats, for some reason when player leaves the game with tool still in hands it doesnt save the old data… so yeah, but thanks for telling me that I can save tables, this is actually pretty useful!
If you run out of queue the data saving will error. However I use my own datastore system which creates a new folder with attributes for every player that joins and would suggest you do that too. Basically every attribute name is the datastore name and its value is the datastore value that’ll be saved to said player. The folder’s name is the player’s ID and it gets removed as the player leaves by saving the data first. It also saves the data for every player loaded in every minute. This is kinda similar to DS2’s cache, but far less confusing. The only part I dislike is the encoding and decoding of data since it has to be a string and not table to be assigned to an attribute.
This is my script, doesn’t tell the full story, but you get the idea.
local DataStoreService = game:GetService("DataStoreService")
local HttpService = game:GetService("HttpService")
local ServerScriptService = game:GetService("ServerScriptService")
local player_event_detection = ServerScriptService:WaitForChild("Player_Event_Detection")
local run_each_x_seconds = ServerScriptService:WaitForChild("Run_Each_X_Seconds")
local datastores = require(script:WaitForChild("Datastores"))
local script_library = require(game:GetService("ServerStorage"):WaitForChild("Script_Library"))
local players_with_ready_data_in_server_storage = {}
local function create_player_data_in_server_storage(player)
local player_data_folder = Instance.new("Folder")
player_data_folder.Name = tostring(player.UserId)
player_data_folder.Parent = script:WaitForChild("Ready_Player_Data")
for datastore_name, default_value in datastores do
local datastore_value = script_library.get_datastore(player, datastore_name)
-- when roblox servers are down this may lead to people having their data reset
--print(player.Name.. "'s returned", datastore_name, "is", datastore_value)
if datastore_value == nil then
datastore_value = default_value
end
if typeof(datastore_value) ~= "table" then
player_data_folder:SetAttribute(datastore_name, datastore_value)
else
player_data_folder:SetAttribute(datastore_name, "JSON".. HttpService:JSONEncode(datastore_value))
end
end
table.insert(players_with_ready_data_in_server_storage, player.UserId)
script:WaitForChild("Ready_Player_Data"):SetAttribute("players_with_ready_data_in_server_storage", HttpService:JSONEncode(players_with_ready_data_in_server_storage))
end
local function save_player_data(player)
local success, error_message = false, nil
local function save_player_data_local_function()
success, error_message = pcall(function()
local player_data_folder = script:WaitForChild("Ready_Player_Data"):WaitForChild(tostring(player.UserId))
for datastore_name, default_value in datastores do
local server_storage_data_value = player_data_folder:GetAttribute(tostring(datastore_name))
if server_storage_data_value == nil then
server_storage_data_value = default_value
end
if typeof(server_storage_data_value) ~= "string" then
script_library.set_datastore(player, datastore_name, server_storage_data_value)
continue
end
if server_storage_data_value:sub(1, 4) ~= "JSON" then
script_library.set_datastore(player, datastore_name, server_storage_data_value)
continue
end
local string_to_decode = string.gsub(server_storage_data_value, "JSON", "", 1)
script_library.set_datastore(player, datastore_name, HttpService:JSONDecode(string_to_decode))
end
end)
end
save_player_data_local_function()
while success == false do
warn(error_message)
task.wait(1)
save_player_data_local_function()
end
end
local function remove_player_data(player)
table.remove(players_with_ready_data_in_server_storage, table.find(players_with_ready_data_in_server_storage, player.UserId))
script:WaitForChild("Ready_Player_Data"):SetAttribute("players_with_ready_data_in_server_storage", HttpService:JSONEncode(players_with_ready_data_in_server_storage))
save_player_data(player)
script:WaitForChild("Ready_Player_Data"):WaitForChild(tostring(player.UserId)):Destroy()
end
local function save_every_player_data()
for _, player in game:GetService("Players"):GetPlayers() do
if table.find(players_with_ready_data_in_server_storage, player.UserId) == nil then continue end
save_player_data(player)
end
end
local function run_each_60_seconds()
save_every_player_data()
end
player_event_detection:WaitForChild("Player_Added").Event:Connect(create_player_data_in_server_storage)
player_event_detection:WaitForChild("Player_Removing").Event:Connect(remove_player_data)
run_each_x_seconds:WaitForChild("60").Event:Connect(run_each_60_seconds)