Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Data store not saving last value?

So I have a data saving script and it used to work great and still does in a way. However, I just recently tried to add another value to the saved values table and it WILL NOT save at all. It seems to save everything else but the last value. Here's the important stuff,

local DataStore = game:GetService("DataStoreService"):GetDataStore("SaveStatsStorage")
game.Players.PlayerAdded:connect(function(Player)
	local key = "player-"..Player.userId
	
	local SavedValues = DataStore:GetAsync(key)
	
	if SavedValues then
		Rounds.Value = SavedValues[1]
		SpongebobMapBeat.Value = SavedValues[2]
		SpaceMapBeat.Value = SavedValues[3]
		MemoryGameBeat.Value = SavedValues[4]
		Points.Value = SavedValues[5]
		MemoryGame2Beat.Value = SavedValues[6]
		Blah.Value = SavedValues[7]
		MarioLevelBeat.Value = SavedValues[8]
		DailyQuestionAnswered3.Value = SavedValues[9]
		PokemonLevelBeat.Value = SavedValues[10]
	else
		local ValuesToSave = {
			Rounds.Value, 
			SpongebobMapBeat.Value, 
			SpaceMapBeat.Value, 
			MemoryGameBeat.Value, 
			Points.Value, 
			MemoryGame2Beat.Value, 
			MarioLevelBeat.Value, 
			DailyQuestionAnswered3.Value, 
			PokemonLevelBeat.Value
			}
		DataStore:SetAsync(key, ValuesToSave)
	end
end)

The PokemonLevelBeat doesn't save. Could it be because the table's too big? Most of the values are bool values. Here's the whole script for context,

local DataStore = game:GetService("DataStoreService"):GetDataStore("SaveStatsStorage")
game.Players.PlayerAdded:connect(function(Player)
	local Stats = Instance.new("IntValue", Player)
	Stats.Name = "leaderstats"
	
	local Blah = Instance.new("BoolValue", Player)
	Blah.Name = "Blah"
	Blah.Value = false
	
	local Rounds = Instance.new("IntValue", Stats)
	Rounds.Name = "RoundsBeaten"
	Rounds.Value = 0
	
	local Points = Instance.new("IntValue", Stats)
	Points.Name = "Points"
	Points.Value = 0
	
	local SpongebobMapBeat = Instance.new("BoolValue",Player)
	SpongebobMapBeat.Name = "SpongebobMapBeat"
	SpongebobMapBeat.Value = false
	
	local SpaceMapBeat = Instance.new("BoolValue",Player)
	SpaceMapBeat.Name = "SpaceMapBeat"
	SpaceMapBeat.Value = false
	
	local MemoryGameBeat = Instance.new("BoolValue",Player)
	MemoryGameBeat.Name = "MemoryGameBeat"
	MemoryGameBeat.Value = false
	
	local MemoryGame2Beat = Instance.new("BoolValue",Player)
	MemoryGame2Beat.Name = "MemoryGame2Beat"
	MemoryGame2Beat.Value = false
	
	local DailyQuestionAnswered3 = Instance.new("BoolValue",Player)
	DailyQuestionAnswered3.Name = "DailyQuestionAnswered3"
	DailyQuestionAnswered3.Value = false
	
	local MarioLevelBeat = Instance.new("BoolValue",Player)
	MarioLevelBeat.Name = "MarioLevelBeat"
	MarioLevelBeat.Value = false
	
	local PokemonLevelBeat = Instance.new("BoolValue",Player)
	PokemonLevelBeat.Name = "PokemonLevelBeat"
	PokemonLevelBeat.Value = false
	
	
	local key = "player-"..Player.userId
	
	local SavedValues = DataStore:GetAsync(key)
	
	if SavedValues then
		Rounds.Value = SavedValues[1]
		SpongebobMapBeat.Value = SavedValues[2]
		SpaceMapBeat.Value = SavedValues[3]
		MemoryGameBeat.Value = SavedValues[4]
		Points.Value = SavedValues[5]
		MemoryGame2Beat.Value = SavedValues[6]
		Blah.Value = SavedValues[7]
		MarioLevelBeat.Value = SavedValues[8]
		DailyQuestionAnswered3.Value = SavedValues[9]
		PokemonLevelBeat.Value = SavedValues[10]
	else
		local ValuesToSave = {
			Rounds.Value, 
			SpongebobMapBeat.Value, 
			SpaceMapBeat.Value, 
			MemoryGameBeat.Value, 
			Points.Value, 
			MemoryGame2Beat.Value, 
			MarioLevelBeat.Value, 
			DailyQuestionAnswered3.Value, 
			PokemonLevelBeat.Value
			}
		DataStore:SetAsync(key, ValuesToSave)
	end
end)

If the table's too big how would I fix this? Here's the player leave save stats script as well just in case that's the problem,

local DataStore = game:GetService("DataStoreService"):GetDataStore("SaveStatsStorage")

game.Players.PlayerRemoving:connect(function(Player)
	
	local key = "player-"..Player.userId
	
	local ValuesToSave = {Player.leaderstats.RoundsBeaten.Value, Player.SpongebobMapBeat.Value, Player.SpaceMapBeat.Value, Player.MemoryGameBeat.Value, Player.leaderstats.Points.Value, Player.MemoryGame2Beat.Value, Player.DailyQuestionAnswered3.Value, Player.MarioLevelBeat.Value, Player.PokemonLevelBeat.Value}
	DataStore:SetAsync(key, ValuesToSave)
end)

Maybe it's how I'm saving the stats? If so, what would be a better way of saving? And help would be AWESOME. This has been such a headache. Sorry for such the long post guys. I hope you can help me.

1 answer

✓ Accepted answer

There's something missing in the ValuesToSave across all your scripts:

local ValuesToSave = {
            Rounds.Value, 
            SpongebobMapBeat.Value, 
            SpaceMapBeat.Value, 
            MemoryGameBeat.Value, 
            Points.Value, 
            MemoryGame2Beat.Value, 
            Blah.Value, -- You forgot this.
            MarioLevelBeat.Value, 
            DailyQuestionAnswered3.Value, 
            PokemonLevelBeat.Value
 }

1 comment

1

OH MEH GOD. Lol, do you know what that was? I'm so stupid. That blah.Value was meant to reset everyone's value to false. Okay, you helped me more than you could have ever imagined. My life expectancy was going down every minute I spent looking at that script. Thanks!

This discussion is preserved as it was. New answers, comments, and votes are closed.