Hey, I’ve been having this issue with my data store. Whenever I leave the game and join back my data isn’t saving properly. you see, I have 3 values saving; materials, coins, and rebirths, but for some reason all 3 values are loading as the coins value. so, if I leave the game with 3 coins, 0 materials, and 0 rebirths, when I join back, they are all set to 2. If someone could help me that would be great. Here is the code.
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("DataStore")
game.Players.PlayerAdded:Connect(function(Player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = Player
-------------------------------------------------
local Materials = Instance.new("IntValue")
Materials.Name = "Materials"
Materials.Parent = leaderstats
local Coins = Instance.new("IntValue")
Coins.Name = "Coins"
Coins.Parent = leaderstats
local Rebirths = Instance.new("IntValue")
Rebirths.Name = "Rebirths"
Rebirths.Parent = leaderstats
local playerUserId = "Player_"..Player.UserId
--Load Data
local CoinsData
local Mats
local Re
local Success, errormessage = pcall(function()
CoinsData = DataStore:GetAsync(playerUserId)
Mats = DataStore:GetAsync(playerUserId)
Re = DataStore:GetAsync(playerUserId)
end)
if Success then
Coins.Value = CoinsData
Materials.Value = Mats
Rebirths.Value = Re
end
end)
-- Save Data
game.Players.PlayerRemoving:Connect(function(player)
local playerUserId = "Player_"..player.UserId
local Coins = player.leaderstats.Coins.Value
local Mats = player.leaderstats.Materials.Value
local Re = player.leaderstats.Rebirths.Value
local success, errormessage = pcall(function()
DataStore:SetAsync(playerUserId, Coins)
DataStore:SetAsync(playerUserId, Mats)
DataStore:SetAsync(playerUserId, Re)
end)
if success then
print("data saved")
else
print("error saving data")
warn(errormessage)
end
end)
roblox studio also nearly crashes every time I leave the game and this pops up in the output:
“DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key = Player_1577295330 (x2)”
The reason for everything loading as the same value is because your not saving them separately, you are just over-writing the different values to the same datastore location. You would need to setup different keys for the different values eg “Player_”…player.UserId…"_Coins".
The best way though (and to fix your other problem of datastore queue) is to simply create a single save file using a table to hold all the values:
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("DataStore")
game.Players.PlayerAdded:Connect(function(Player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = Player
-------------------------------------------------
local Materials = Instance.new("IntValue")
Materials.Name = "Materials"
Materials.Parent = leaderstats
local Coins = Instance.new("IntValue")
Coins.Name = "Coins"
Coins.Parent = leaderstats
local Rebirths = Instance.new("IntValue")
Rebirths.Name = "Rebirths"
Rebirths.Parent = leaderstats
local playerUserId = "Plr_"..Player.UserId
--Load Data
local PlrData
local Success, errormessage = pcall(function()
PlrData = DataStore:GetAsync(playerUserId)
end)
if Success then
Coins.Value = PlrData.Coins
Materials.Value =PlrData.Mats
Rebirths.Value = PlrData.Re
end
end)
-- Save Data
game.Players.PlayerRemoving:Connect(function(player)
local playerUserId = "Plr_"..player.UserId
local PlrData={Coins=player.leaderstats.Coins.Value, Mats=player.leaderstats.Materials.Value, Re=player.leaderstats.Rebirths.Value}
local success, errormessage = pcall(function()
DataStore:SetAsync(playerUserId, PlrData)
end)
if success then
print("data saved")
else
print("error saving data")
warn(errormessage)
end
end)
after editing the code to what you did, now I’m having errors saving the code and getting an orange error message saying: “HTTP 500 (Internal Server Error)” Is this an ongoing issue within the code or just a Roblox issue that will resolve itself sooner or later? im also still having the “data request was added to queue” even know all the values are inside of that table.