I want to save different datastores in one datastore.
Currently I have four different datastores for saving data and if I add more I get a warning: “DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.” Another problem with multiple datastores is it lags when I stop testing in studio.
Script in ServerScriptService:
local DataStore = game:GetService("DataStoreService")
local LevelsDatastore = DataStore:GetDataStore("Levels003")
local GoldDataStore = DataStore:GetDataStore("Gold003")
local ExperienceDatastore = DataStore:GetDataStore("Exp003")
local ExperienceNeededDatastore = DataStore:GetDataStore("ExpNeed003")
game.Players.PlayerAdded:Connect(function(Plr)
local statsFolder = Instance.new("Folder", Plr)
statsFolder.Name = "Data"
local leaderstatsFolder = Instance.new("Folder", Plr)
leaderstatsFolder.Name = "leaderstats"
local Levels = Instance.new("IntValue", leaderstatsFolder)
Levels.Name = "Levels"
Levels.Value = 1
local Exp = Instance.new("IntValue", statsFolder)
Exp.Name = "Exp"
Exp.Value = 0
local ExpNeed = Instance.new("IntValue", statsFolder)
ExpNeed.Name = "ExpNeed"
ExpNeed.Value = 200
local Gold = Instance.new("IntValue", leaderstatsFolder)
Gold.Name = "Gold"
Gold.Value = 0
Levels.Value = LevelsDatastore:GetAsync(Plr.UserId) or Levels.Value
LevelsDatastore:SetAsync(Plr.UserId, Levels.Value)
Levels.Changed:connect(function()
LevelsDatastore:SetAsync(Plr.UserId, Levels.Value)
end)
Gold.Value = GoldDataStore:GetAsync(Plr.UserId) or Gold.Value
GoldDataStore:SetAsync(Plr.UserId, Gold.Value)
Gold.Changed:connect(function()
GoldDataStore:SetAsync(Plr.UserId, Gold.Value)
end)
Exp.Value = ExperienceDatastore:GetAsync(Plr.UserId) or Exp.Value
ExperienceDatastore:SetAsync(Plr.UserId, Exp.Value)
Exp.Changed:connect(function()
ExperienceDatastore:SetAsync(Plr.UserId, Exp.Value)
end)
ExpNeed.Value = ExperienceNeededDatastore:GetAsync(Plr.UserId) or ExpNeed.Value
ExperienceNeededDatastore:SetAsync(Plr.UserId, ExpNeed.Value)
ExpNeed.Changed:connect(function()
ExperienceNeededDatastore:SetAsync(Plr.UserId, ExpNeed.Value)
end)
end)
game.Players.PlayerAdded:Connect(function(plr)
local DataFolder = plr:WaitForChild("Data")
local leaderstatsFolder = plr:WaitForChild("Data")
local Exp = DataFolder:WaitForChild("Exp")
local Levels = leaderstatsFolder:WaitForChild("Levels")
local ExpNeed = DataFolder:WaitForChild("ExpNeed")
while wait() do
if Exp.Value >= (100 * (Levels.Value + 1)) and Levels.Value <= 399 then
Levels.Value = Levels.Value + 1
Exp.Value = Exp.Value - ExpNeed.Value
ExpNeed.Value = ExpNeed.Value + 100
game.ReplicatedStorage.LevelSystem.LevelUpGui:FireClient(plr)
end
end
end)
game.Players.PlayerRemoving:connect(function(Player)
LevelsDatastore:SetAsync(Player.UserId, Player.leaderstats.Levels.Value)
GoldDataStore:SetAsync(Player.UserId, Player.leaderstats.Gold.Value)
ExperienceDatastore:SetAsync(Player.UserId, Player.Data.Exp.Value)
ExperienceNeededDatastore:SetAsync(Player.UserId, Player.Data.ExpNeed.Value)
end)
With my current way the data just gets set to zero.
How I currently load data:
Levels.Value = EverythingDatastore:GetAsync(Plr.UserId) or Levels.Value
Gold.Value = EverythingDatastore:GetAsync(Plr.UserId) or Gold.Value
Exp.Value = EverythingDatastore:GetAsync(Plr.UserId) or Exp.Value
ExpNeed.Value = EverythingDatastore:GetAsync(Plr.UserId) or ExpNeed.Value
Nevermind I figured it out all I had to do is put [#] at the end of the getasyncfunction
Levels.Value = EverythingDatastore:GetAsync(Plr.UserId)[3] or Levels.Value
Gold.Value = EverythingDatastore:GetAsync(Plr.UserId)[1] or Gold.Value
Exp.Value = EverythingDatastore:GetAsync(Plr.UserId)[4] or Exp.Value
ExpNeed.Value = EverythingDatastore:GetAsync(Plr.UserId)[2] or ExpNeed.Value