Suddenly my datastore code changed even though I never modified it. It only saves the data once and doesn't save it again. It loads perfectly fine, though. I've tried different ASyncs, changed datastore name (effectively wiping my data which is how I figured out it only saves once), and I just can't seem to figure it out. I need help. I believe that the issue may lie in the function that saves when the player leaves.
--Variables. local DSS = game:GetService("DataStoreService"):GetDataStore("Breathing Simulator DataStore") -- Adding statistics to a player when they join. game.Players.PlayerAdded:Connect(function(Player) local PlayerID = tostring(Player.userId) local Statistics = Instance.new("Folder",Player) Statistics.Name = "Statistics" local Roobil = Instance.new("NumberValue",Statistics) Roobil.Name = "Roobils" Roobil.Value = 0 local AbbreviatedRoobil = Instance.new("StringValue",Statistics) AbbreviatedRoobil.Name = "Abbreviated Roobils" AbbreviatedRoobil.Value = "Roobil" local MoltenRoobil = Instance.new("NumberValue",Statistics) MoltenRoobil.Name = "Molten Roobil" MoltenRoobil.Value = 0 local AbbreviatedMoltenRoobil = Instance.new("StringValue",Statistics) AbbreviatedMoltenRoobil.Name = "Abbreviated Molten Roobil" AbbreviatedMoltenRoobil.Value = "Pints of Molten Roobil" local MoltenRoobilPerBreath = Instance.new("NumberValue",Statistics) MoltenRoobilPerBreath.Name = "Molten Roobil Per Breath" MoltenRoobilPerBreath.Value = 0.01 local Gases = Instance.new("Folder",Statistics) Gases.Name = "Gases" local Oxygen = Instance.new("BoolValue",Gases) Oxygen.Name = "Oxygen" Oxygen.Value = true local CarbonDioxide = Instance.new("BoolValue",Gases) CarbonDioxide.Name = "Carbon Dioxide" CarbonDioxide.Value = false local Helium = Instance.new("BoolValue",Gases) Helium.Name = "Helium" Helium.Value = false local GetSaved = DSS:GetAsync(PlayerID) -- Loading their data if they have any. if GetSaved then Roobil.Value = GetSaved[1] MoltenRoobil.Value = GetSaved[2] CarbonDioxide.Value = GetSaved[3] Helium.Value = GetSaved[4] Roobil.Value = GetSaved[1] MoltenRoobil.Value = GetSaved[2] CarbonDioxide.Value = GetSaved[3] Helium.Value = GetSaved[4] -- If they don't, get new dat and save it.. else local NumbersForSaving = {Roobil.Value,MoltenRoobil.Value,CarbonDioxide.Value,Helium.Value} DSS:SetAsync(PlayerID,NumbersForSaving) end end) -- When a player leaves, grab all the things you want to save and save them. game.Players.PlayerRemoving:Connect(function(Player) local Statistics = Player:WaitForChild("Statistics") local Gases = Statistics:WaitForChild("Gases") local Roobil = Statistics:WaitForChild("Roobils") local MoltenRoobil = Statistics:WaitForChild("Molten Roobil") local CarbonDioxide = Gases:WaitForChild("Carbon Dioxide") local Helium = Gases:WaitForChild("Helium") local PlayerID = tostring(Player.userId) local NumbersForSaving = {Roobil.Value,MoltenRoobil.Value,CarbonDioxide.Value,Helium.Value} DSS:SetAsync(PlayerID,NumbersForSaving) end)
I managed to fix this. I used datastores that had single value storage, and then individually saved the values to each of them and took them out. This worked.