#DataStore request was added to queue
17 messages · Page 1 of 1 (latest)
-- Function to save player data to the DataStore
local function savePlayerData(player)
local plrkey = "id_" .. player.UserId
local savevalue = player.leaderstats["Jump Height"]
local savevalue2 = player.leaderstats.Wins
local savevalue3 = player.Gravity
local NumbersForSaving = {
savevalue.Value,
savevalue2.Value,
savevalue3.Value,
}
DS:SetAsync(plrkey, NumbersForSaving)
end
game.Players.PlayerAdded:Connect(function(plr)
wait()
-- Load player data from the DataStore
local plrkey = "id_" .. plr.UserId
local GetSaved = DS:GetAsync(plrkey)
if GetSaved then
local savevalue = plr.leaderstats["Jump Height"]
local savevalue2 = plr.leaderstats.Wins
local savevalue3 = plr.Gravity
-- Set values from the DataStore
savevalue.Value = GetSaved[1]
savevalue2.Value = GetSaved[2]
savevalue3.Value = GetSaved[3]
else
local savevalue = Instance.new("NumberValue", plr)
savevalue.Name = "Jump Height"
local savevalue2 = Instance.new("IntValue", plr)
savevalue2.Name = "Wins"
local savevalue3 = Instance.new("NumberValue", plr)
savevalue3.Name = "Gravity"
end
wait(1)
if plr["Gravity"].Value == 0 then
plr["Gravity"].Value = 196.2
end
if plr.leaderstats["Jump Height"].Value > 0 then
repeat
wait()
until plr.Character
wait(0.5)
plr.Character.Humanoid.JumpHeight = plr.leaderstats["Jump Height"].Value
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
savePlayerData(plr)
print("Left Successfully")
end)
game:BindToClose(function()
for _, plr in pairs(game.Players:GetPlayers()) do
savePlayerData(plr)
plr:Kick()
print("Left Successfully")
end
end)```
can anyone tell what is wrong?
@left jacinth i recommend adding some error handling.
error handling to the SetAsync and GetAsync methods
You can use pcall to call the SetAsync and GetAsync
Tried it but i still get the same warning
The warning message you're seeing is related to the rate at which you're sending requests to the DataStore. To fix this, you can implement rate limiting by introducing a delay between each request.
Here's an updated version of your script that includes rate limiting:
local DS = game:GetService("DataStoreService"):GetDataStore("DataStoreName-1")
local MAX_REQUESTS_PER_MINUTE = 10 -- Adjust this value as needed
local function savePlayerData(player)
local plrkey = "id_" .. player.UserId
local savevalue = player.leaderstats["Jump Height"]
local savevalue2 = player.leaderstats.Wins
local savevalue3 = player.Gravity
local NumbersForSaving = {
savevalue.Value,
savevalue2.Value,
savevalue3.Value,
}
DS:SetAsync(plrkey, NumbersForSaving)
end
game.Players.PlayerAdded:Connect(function(plr)
wait()
local plrkey = "id_" .. plr.UserId
local GetSaved = DS:GetAsync(plrkey)
if GetSaved then
local savevalue = plr.leaderstats["Jump Height"]
local savevalue2 = plr.leaderstats.Wins
local savevalue3 = plr.Gravity
savevalue.Value = GetSaved[1]
savevalue2.Value = GetSaved[2]
savevalue3.Value = GetSaved[3]
else
local savevalue = Instance.new("NumberValue", plr)
savevalue.Name = "Jump Height"
local savevalue2 = Instance.new("IntValue", plr)
savevalue2.Name = "Wins"
local savevalue3 = Instance.new("NumberValue", plr)
savevalue3.Name = "Gravity"
end
wait(1)
if plr["Gravity"].Value == 0 then
plr["Gravity"].Value = 196.2
end
if plr.leaderstats["Jump Height"].Value > 0 then
repeat
wait()
until plr.Character
wait(0.5)
plr.Character.Humanoid.JumpHeight = plr.leaderstats["Jump Height"].Value
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
savePlayerData(plr)
print("Left Successfully")
end)
game:BindToClose(function()
local players = game.Players:GetPlayers()
local numPlayers = #players
local requestsSent = 0
for _, plr in ipairs(players) do
savePlayerData(plr)
plr:Kick()
requestsSent = requestsSent + 1
if requestsSent >= numPlayers or requestsSent >= MAX_REQUESTS_PER_MINUTE then
break
end
end
print("Left Successfully")
end)
@left jacinth
u need help