DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key = 1841046685
This is the error i keep repeating,I dont know what is wrong with my script.
DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key = 1841046685
This is the error i keep repeating,I dont know what is wrong with my script.
Try sending fewer requests. Only save player data when they leave
How often are you saving data? You should probably save:
BindToClose
)If you already have a BindToClose
function, make sure the current environment isn’t studio, so you don’t try to save two sets of data at once.
local runService = game:GetService("RunService")
local players = game:GetService("Players")
game:BindToClose(function()
if runService:IsStudio() then task.wait(3) return nil end
for _, player in ipairs(players:GetPlayers()) do
--save player data
end
task.wait(3)
end)
local datastoreservice = game:GetService(“DataStoreService”)
local mystore = datastoreservice:GetDataStore(“IHopeTheProblemIsFixed”)
local RunService = game:GetService(“RunService”)
local RS = game:GetService(“ReplicatedStorage”)
local mps = game:GetService(“MarketplaceService”)
local GameEvents = RS.GameEvents
local ToolEvent = GameEvents.ToolEvent
local Players = game:GetService(“Players”)
local DoubleCoinID = 735487076
local DoubleGemsID = 739787781
local productFunctions = {}
–Quest Events
local QuestEvents = RS.QuestEvents
local Quest1Event = QuestEvents.Quest1Event
local Quest2Event = QuestEvents.Quest2Event
mps.PromptGamePassPurchaseFinished:Connect(function(plr,ido,purchased)
if purchased and DoubleCoinID == ido then
local GamePassesValue = RS.Values.GamePassesValue
local CoinsValue = GamePassesValue.CoinsValue
CoinsValue.Value = (CoinsValue.Value * 2)
end
end)
mps.PromptGamePassPurchaseFinished:Connect(function(plr,ido,purchased)
if purchased and DoubleGemsID == ido then
local GamePassesValue = RS.Values.GamePassesValue
local GemsValue = GamePassesValue.GemsValue
GemsValue.Value = (GemsValue.Value * 2)
end
end)
mps.PromptGamePassPurchaseFinished:Connect(function(plr,ido,purchased)
if purchased and DoubleGemsID == ido then
local GamePassesValue = RS.Values.GamePassesValue
local GemsValue = GamePassesValue.GemsValue
GemsValue.Value = (GemsValue.Value * 2)
end
end)
–Developer Products
–Kills All players except the player itself
productFunctions[1770656080] = function(receiptinfo, player)
print(“Checked”)
local Players = game:GetService(“Players”)
local player = Players:GetPlayerByUserId(receiptinfo.PlayerId)
for i , v in pairs(game.Players:GetChildren()) do
if v ~= player then
print("correct")
wait(1)
local character = v.Character
if v.Character then
local humanoid = character:WaitForChild("Humanoid")
if humanoid then
humanoid.Health = 0
end
end
end
end
RS.GameEvents.KillAllEvent:FireAllClients(player.Name)
return Enum.ProductPurchaseDecision.PurchaseGranted
end
–Gives One Thousand Coins
productFunctions[1771431678] = function(receipt, player)
local leaderstats = player:WaitForChild(“leaderstats”)
local Coins = leaderstats and leaderstats:WaitForChild(“Coins”)
if Coins then
Coins.Value += 1000
return true
end
end
–Gives One Thousand Coins
productFunctions[1771436973] = function(receipt, player)
local leaderstats = player:WaitForChild(“leaderstats”)
local Coins = leaderstats and leaderstats:WaitForChild(“Coins”)
if Coins then
Coins.Value += 10000
return true
end
end
local function processReceipt(receiptInfo)
local userId = receiptInfo.PlayerId
local productId = receiptInfo.ProductId
local player = Players:GetPlayerByUserId(userId)
if player then
-- Get the handler function associated with the developer product ID and attempt to run it
local handler = productFunctions[productId]
local success, result = pcall(handler, receiptInfo, player)
if success then
wait(1)
-- The user has received their benefits
-- Return "PurchaseGranted" to confirm the transaction
return Enum.ProductPurchaseDecision.PurchaseGranted
else
warn("Failed to process receipt:", receiptInfo, result)
end
end
-- The user's benefits couldn't be awarded
-- Return "NotProcessedYet" to try again next time the user joins
return Enum.ProductPurchaseDecision.NotProcessedYet
end
– Set the callback; this can only be done once by one server-side script
mps.ProcessReceipt = processReceipt
game.Players.PlayerAdded:Connect(function(player)
local Values = RS.Values
local QuestValue = Values.QuestValue
local Quest1Value = QuestValue.Quest1Value
local Quest2Value = QuestValue.Quest2Value
local leaderstats = Instance.new("Folder",player)
leaderstats.Name = "leaderstats"
local coins = Instance.new("IntValue",leaderstats)
coins.Name = "Coins"
coins.Value = 0
local gems = Instance.new("IntValue",leaderstats)
gems.Name = "Gems"
gems.Value = 0
local data
local found, new = pcall(function()
data = mystore:GetAsync(player.UserId)
print(mystore:GetChildren())
end)
if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, DoubleCoinID) then
local GamePassesValue = RS.Values.GamePassesValue
local CoinsValue = GamePassesValue.CoinsValue
CoinsValue.Value = (CoinsValue.Value * 2)
end
if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, DoubleGemsID) then
local GamePassesValue = RS.Values.GamePassesValue
local GemsValue = GamePassesValue.GemsValue
GemsValue.Value = (GemsValue.Value * 2)
end
Quest1Event.OnServerEvent:Connect(function(plr,rewardCoin)
wait(1)
if Quest1Value.Value == "CompletedVeryEasy" then
if rewardCoin == 20 then
player.leaderstats.Coins.Value += 20
Quest1Value.Value = "nil"
end
elseif Quest1Value.Value == "CompletedEasy" then
if rewardCoin == 80 then
player.leaderstats.Coins.Value += 80
Quest1Value.Value = "nil"
end
elseif Quest1Value.Value == "CompletedMedium" then
if rewardCoin == 200 then
player.leaderstats.Coins.Value += 200
Quest1Value.Value = "nil"
end
end
Quest1Event:FireClient(player)
end)
Quest2Event.OnServerEvent:Connect(function(plr,rewardCoin)
wait(1)
if Quest2Value.Value == "CompletedVeryEasy" then
if rewardCoin == 20 then
player.leaderstats.Coins.Value += 20
Quest2Value.Value = "nil"
end
elseif Quest2Value.Value == "CompletedEasy" then
if rewardCoin == 80 then
player.leaderstats.Coins.Value += 80
Quest2Value.Value = "nil"
end
elseif Quest2Value.Value == "CompletedMedium" then
if rewardCoin == 200 then
player.leaderstats.Coins.Value += 200
Quest1Value.Value = "nil"
end
end
Quest1Event:FireClient(player)
end)
if data then
coins.Value = data.Coins
gems.Value = data.Gems
else
coins.Value = 0
gems.Value = 0
end
end)
–save the players data here, basically what you did in playerRemoving.
game.Players.PlayerRemoving:Connect(function(player)
local datatobesaved = {
Coins = player.leaderstats.Coins.Value;
Gems = player.leaderstats.Gems.Value;
}
local success, err = pcall(function()
mystore:SetAsync(player.UserId,datatobesaved)
print(mystore:GetChildren())
end)
if success then
print("data saved!")
else
warn(err)
print("data faield to save!")
end
end)
game:BindToClose(function()
if RunService:IsStudio() then
wait(1)
else
for _,localplayer in pairs(Players) do -- Loop through All Players in game
local datatobesaved = {
Coins = localplayer.leaderstats.Coins.Value;
Gems = localplayer.leaderstats.Gems.Value;
}
local success, Error = pcall(function() -- Wrap in Pcall so script does not break in case of an error
mystore:SetAsync(localplayer.UserId,{ -- Save Data With UserId
datatobesaved
})
end)
if not success then warn(Error) end -- If we get An Error while Saving, We "Warn" it, Which tells us what caused the error.
end
end
end)
This is my entire script
(300 ++ Lines long)
I dont think that PlayerRemoving
works in studio since the server is shut down immedietaly
It does, if you wait in the BindToClose
(which is probably a good idea anyway, so the DataStore
requests definitely go through). It works for me, at least.
BindToClose
runs the provided code before game shutdown, so a yield should delay it.
How to use yield script,Can u show me the yield thing