Hi I keep receiving this error on my House Data Store system: DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key. Script:
local DataStoreService = game:GetService("DataStoreService")
local MainData = DataStoreService:GetDataStore("MainData")
local HouseData = DataStoreService:GetDataStore("HouseData")
--Variables--
function saveHouseData(player)
local Houses = {}
for i, value in pairs(player.Houses:GetChildren()) do
Houses[value.Name] = value.Value
end
HouseData:SetAsync(player.UserId, Houses)
end
--House Data--
game.Players.PlayerAdded:Connect(function(player)
local Plot = Instance.new("StringValue")
Plot.Name = "Plot"
Plot.Value = ""
Plot.Parent = player
local Houses = Instance.new("Folder")
Houses.Name = "Houses"
Houses.Parent = player
for i, house in pairs(game.ReplicatedStorage.Houses:GetChildren()) do
local newValue = Instance.new("BoolValue")
newValue.Name = house.Name
newValue.Value = false
newValue.Parent = Houses
end
local houseData = HouseData:GetAsync(player.UserId) or {}
for houseName, houseValue in pairs(HouseData)
Houses[houseName].Value = houseValue
end
end)
--House Saving--
game.Players.PlayerRemoving:Connect(function(player)
if game.Workspace:FindFirstChild(player.Name.."'sHouse") then
game.Workspace:FindFirstChild(player.Name.."'sHouse"):Destroy()
end
local PlayerPlot = player.Plot
game.Workspace:FindFirstChild(PlayerPlot.Value).CurrentOwner.Value = ""
player.Plot.Value = ""
end)
game.Players.PlayerRemoving:Connect(saveHouseData)
game:BindToClose(function()
for i, player in pairs(game.Players:GetPlayers()) do
saveHouseData(player)
end
end)
Updated
I got rid of all errors datastore still doesn't work here is the updated code
local DataStoreService = game:GetService("DataStoreService")
local MainData = DataStoreService:GetDataStore("MainData")
local HouseData = DataStoreService:GetDataStore("HouseData")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local function waitForRequestBudget(requestType: Enum.DataStoreRequestType)
local currentBudget = DataStoreService:GetRequestBudgetForRequestType(requestType)
while currentBudget < 1 do
currentBudget = DataStoreService:GetRequestBudgetForRequestType(requestType)
task.wait(5)
end
end
-- House Data --
game.Players.PlayerAdded:Connect(function(player)
local Plot = Instance.new("StringValue")
Plot.Name = "Plot"
Plot.Value = ""
Plot.Parent = player
local Houses = Instance.new("Folder")
Houses.Name = "Houses"
Houses.Parent = player
for i, house in pairs(ReplicatedStorage.Houses:GetChildren()) do
local newValue = Instance.new("BoolValue")
newValue.Name = house.Name
newValue.Value = false
newValue.Parent = Houses
end
end)
function loadHouseData(player)
local Houses = Players.Houses
waitForRequestBudget(Enum.DataStoreRequestType.GetAsync)
local success, houseData = pcall(HouseData.GetAsync, HouseData, player.UserId)
if success then
for houseName, houseValue in pairs(HouseData) do
Houses[houseName].Value = houseValue
end
else -- if it errors (mostly when player has no data)
print("Player " .. player.Name .. " has no data!")
warn(houseData) -- warns the error message
end
end
-- House Saving --
function saveHouseData(player)
local Houses = {}
local success
repeat
waitForRequestBudget(Enum.DataStoreRequestType.UpdateAsync)
success = pcall(HouseData.UpdateAsync, HouseData, player.UserId, function()
return Houses
end)
until success
if workspace:FindFirstChild(player.Name.."'sHouse") then
game.Workspace:FindFirstChild(player.Name.."'sHouse"):Destroy()
end
local Plot = player.Plot
local PlayerPlot = player.Plot
workspace:FindFirstChild(Plot)player.Plot.Value = ""
player.Plot.Value = ""
local Houses = {}
for i, value in pairs(player.Houses:GetChildren()) do
Houses[value.Name] = value.Value
end
end
for _, player in ipairs(Players:GetPlayers()) do
coroutine.wrap(loadHouseData)(player)
end
game.Players.PlayerAdded:Connect(function(loadHouseData)
game.Players.PlayerRemoving:Connect(saveHouseData)
game:BindToClose(function()
if RunService:IsStudio() then
task.wait(2)
print("task waited")
else
local finished = Instance.new("BindableEvent")
local allPlayers = Players:GetPlayers()
local leftPlayers = #allPlayers
for _, player in ipairs(allPlayers) do
coroutine.wrap(function()
saveHouseData(player)
leftPlayers -= 1
if leftPlayers == 0 then
finished:Fire()
print("finishing")
end
end)()
end
finished.Event:Wait()
end
end)
end)

1 comment
Sorry about the spacing I sent the code to my other computer to post it and the format gets weird