can anyone pls explain to me why the trails dont save and i get this warning when i leave the game?
warning: DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key = player_396958652
Players.PlayerAdded:Connect(function(player)
local PlayerTrails = Instance.new("Folder",player)
PlayerTrails.Name = "PlayerTrails"
local TrailsFile = ServerStorage:WaitForChild("Trails")
local data
local success, Error = pcall(function()
data = DataStore:GetAsync("player_"..player.UserId)
end)
if success then
if data.trails then
print("idk")
for _, object in (data.trails) do
print(object)
end
for _, trail in pairs(TrailsFile:GetChildren()) do
for _, TrailName in pairs(data.trails) do
if trail.Name == TrailName then
local TrailClone = trail:Clone()
TrailClone.Parent = PlayerTrails
print(trail.Name)
end
end
end
print("loadded trails")
end
else
print("there was an error while loading player trails")
warn(Error)
end
end
Players.PlayerRemoving:Connect(function(player)
local PlayerTrails = player:WaitForChild("PlayerTrails")
if #PlayerTrails:GetChildren() == 0 then return end
local data
local success, Error = pcall(function()
data = DataStore:GetAsync("player_"..player.UserId)
end)
data.Trails = data.Trails or {}
if data.trails then
for _, TrailName in pairs(data.trails) do
for _,trail in pairs(PlayerTrails:GetChildren()) do
if trail.Name == TrailName then break end
table.insert(data.trails, trail.Name)
end
end
end
local success, Erorr = pcall(function()
DataStore:SetAsync("player_"..player.UserId,data)
end)
if success then
print("saved trails successfully")
else
print("there was an error while saving player trails")
warn(Erorr)
end
end)
The request added to queue warning doesn’t mean it actually failed if that’s what you’re seeing.
It’s just a throttle so you don’t overload the servers.
the warning was because i saved to the same datasore drom two different scripts
and here is the fixed script:
Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder",player)
leaderstats.Name = "leaderstats"
local Money = Instance.new("IntValue",leaderstats)
Money.Name = "Money"
Money.Value = 0
local Wins = Instance.new("IntValue",leaderstats)
Wins.Name = "Wins"
Wins.Value = 0
local PlayerTrails = Instance.new("Folder",player)
PlayerTrails.Name = "PlayerTrails"
local TrailsFile = ServerStorage:WaitForChild("Trails")
-- load saved data
local data
local success, ErrorMsg = pcall(function()
data = DataStore:GetAsync("player_"..player.UserId)
end)
if success and data then
-- load leaderstats values
Money.Value = data["Money"]
Wins.Value = data["Wins"]
-- load trails
for _, trail in pairs(TrailsFile:GetChildren()) do
for _, TrailName in pairs(data.trails) do
if trail.Name == TrailName then
local TrailClone = trail:Clone()
TrailClone.Parent = PlayerTrails
print(trail.Name)
end
end
end
else
print("there was an error while loading player data")
warn(ErrorMsg)
end
local PlayerGui = player:WaitForChild("PlayerGui")
local ScrollingFrame = PlayerGui:WaitForChild("TrailsGui"):WaitForChild("TrailsFrame"):WaitForChild("ScrollingFrame")
for _,trail in pairs(PlayerTrails:GetChildren()) do
for _, TrailImage in pairs(ScrollingFrame:GetChildren()) do
if TrailImage:IsA("ImageLabel") and TrailImage.Name == trail.Name then
TrailImage.EquipButton.Text = "Equip"
TrailImage.PriceText.Visible = false
end
end
end
end)
Players.PlayerRemoving:Connect(function(player)
local Money = player.leaderstats.Money
local Wins = player.leaderstats.Wins
local PlayerTrails = player:WaitForChild("PlayerTrails")
local data
data = {Money = Money.Value, Wins = Wins.Value}
data.trails = data.trails or {}
if #PlayerTrails:GetChildren() > 0 then
for i,trail in pairs(PlayerTrails:GetChildren()) do
if table.find(data.trails, trail.Name) == nil then
print(trail.Name)
table.insert(data.trails, trail.Name)
end
end
end
local success, ErrorMsg = pcall(function()
DataStore:SetAsync("player_"..player.UserId, data)
end)
if success == false then
print("there was an error while saving players data")
warn(ErrorMsg)
end
end)