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!
I want to figure out why the script fills the data store queue on the first variable and doesn’t move on
What is the issue? Include screenshots / videos if possible!
The script fills the data store queue on the first variable and doesn’t move on
It says DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key = 559935534Strength - Studio
and Strength is the first variable saved
Script:
game.Players.PlayerRemoving:Connect(function(player)
local playerUserId=player.UserId
local OV=player.OV
local OVVariables=OV:GetChildren()
for i, variable in pairs(OVVariables) do
print(variable.Value)
local setSuccess, errorMessage = pcall(function()
VariableDataStore:SetAsync(playerUserId..variable.Name,variable.Value)
end)
if not setSuccess then
warn(errorMessage)
end
end
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have tried putting a wait function and looking for solutions on the forum but none of those have worked.
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!
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.
Alright i see the problem
You save it so many times and i would suggest you to save only array with thouse variables and when the player joins just load them also you have there OV but i have sidesalad
local DataStoreService = game:GetService("DataStoreService")
local playerData = DataStoreService:GetDataStore("PlayerData")
local runService = game:GetService("RunService")
local function onPlayerJoin(player) -- Runs when players join
local sidesalad = Instance.new("Folder")
sidesalad.Name = "sidesalad"
sidesalad.Parent = player
local lvl = Instance.new("IntValue")
lvl.Name = "lvl"
lvl.Parent = sidesalad
local Str = Instance.new("IntValue")
Str.Name = "Str"
Str.Parent = sidesalad
local Mana = Instance.new("IntValue")
Mana.Name = "Mana"
Mana.Parent = sidesalad
local Health = Instance.new("IntValue")
Health.Name = "Health"
Health.Parent = sidesalad
local Stamina = Instance.new("IntValue")
Stamina.Name = "Stamina"
Stamina.Parent = sidesalad
local StatPoints = Instance.new("IntValue")
StatPoints.Name = "StatPoints"
StatPoints.Parent = sidesalad
local dr = Instance.new("IntValue")
dr.Name = "dr"
dr.Parent = sidesalad
local exp = Instance.new("IntValue")
exp.Name = "exp"
exp.Parent = sidesalad
local maxexp = Instance.new("IntValue")
maxexp.Name = "maxexp"
maxexp.Parent = sidesalad
local class = Instance.new("StringValue")
class.Name = "class"
class.Parent = sidesalad
--local function upgradestats()
-- lvl.Value = lvl.Value + 1
-- dr.Value = dr.Value + lvl.Value / 100
-- print(player.Name,"Has just got Level up! And now he got",lvl.Value,"Lvl")
--end
--exp:GetPropertyChangedSignal("Value"):Connect(function()
-- if maxexp.Value == 0 then
-- maxexp.Value = 5
-- end
-- if exp.Value == maxexp.Value then
-- exp.Value = 0
-- maxexp.Value = maxexp.Value * 1.25
-- upgradestats()
-- elseif exp.Value >= maxexp.Value then
-- local a = Instance.new("IntValue")
-- a.Name = "бебра"
-- a.Parent = sidesalad
-- a.Value = exp.Value
-- exp.Value = 0
-- while a.Value > maxexp.Value do
-- if a.Value > maxexp.Value then
-- a.Value = a.Value - maxexp.Value
-- maxexp.Value = maxexp.Value * 1.25
-- upgradestats()
-- end
-- end
-- exp.Value = a.Value
-- print("Your exp now = ",exp.Value)
-- a:Destroy()
-- end
--end)
local playerUserId = "Player_" .. player.UserId --Gets player ID
local data = playerData:GetAsync(playerUserId) --Checks if player has stored data
if data then
lvl.Value = data['lvl']
Str.Value = data['Str']
dr.Value = data['dr']
class.Value = data['class']
Health.Value = data['Health']
Mana.Value = data['Mana']
maxexp.Value = data["maxexp"]
exp.Value = data['exp']
Stamina.Value = data["Stamina"]
StatPoints.Value = data["StatPoints"]
else
Health.Value = 1
maxexp.Value = 5
lvl.Value = 1
StatPoints.Value = 3 -- sets the values to standart it's for not to have your lvl 0 or health 0
end
end
local function create_table(player)
local player_stats = {}
for _, stat in pairs(player.sidesalad:GetChildren()) do
player_stats[stat.Name] = stat.Value
end
return player_stats
end
local function onPlayerExit(player) --Runs when players exit
local player_stats = create_table(player)
local success, err = pcall(function()
local playerUserId = "Player_" .. player.UserId
playerData:SetAsync(playerUserId, player_stats) --Saves player data
end)
if not success then
warn('Could not save data!')
print(err)
end
end
game.Players.PlayerAdded:Connect(onPlayerJoin)
game.Players.PlayerRemoving:Connect(onPlayerExit)
game:BindToClose(function()
wait(10)
end)
``