My data stores isn't loading the correct things

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    so um my data stores are saving perfectly, it saves all the correct data and stuff. BUT when loading it loads some wrong values

  2. What is the issue? Include screenshots / videos if possible!
    It’s loading old Data for some reason and on rare occasions, it wouldn’t save

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I’ve been solo on this whole thing, this was working like 10 minutes ago and now it’s not, I’ve been using the dev forums for answers.

(the J stands for jetpack and the R stands for Radio)

local Players, DataStoreService = game:GetService("Players"), game:GetService("DataStoreService")
local ColorStorage = DataStoreService:GetDataStore("ColorManager")

local function load(player: Player)
	local PlayerUserId = 'Player_'.. player.UserId
	local Data = ColorStorage:GetAsync(PlayerUserId)
	if Data then
		local remoteEvent = player.Parent.Parent.StarterPlayer.StarterCharacterScripts.Radio.ServerToclient
		local remoteEvent2 = player.Parent.Parent.StarterPlayer.StarterCharacterScripts.JetPack.ServerToclient
		print("load Data")
		if Data['PrimaryColorJ'] ~= nil then
			local Jcolor1 =['PrimaryColorJ']))
			local Jcolor2 =['SecondaryColorJ']))
			local Jcolor3 =['ThirdColorJ']))
			remoteEvent2:FireClient(player, Jcolor1, Jcolor2, Jcolor3)
		if Data['PrimaryColorR'] ~= nil then
			local Rcolor1 =['PrimaryColorR']))
			local Rcolor2 =['SecondaryColorR']))
			remoteEvent:FireClient(player, Rcolor1, Rcolor2)

local function colortable(player)
	local colorsTable = {}
	local Found1 = Players:WaitForChild("JetPack")
	local Found2 = Players:WaitForChild("BoomBox")
	if Found1 and Found2 then
		for _, ColorValues in pairs(Found1.Jetpack.MainParts:GetChildren()) do
			colorsTable[ColorValues.Name] = tostring(ColorValues.Color):split(", ")
			print(tostring(ColorValues.Color):split(", "))
		for _, ColorValues in pairs(Found2.BoomBox.MainParts:GetChildren()) do
			colorsTable[ColorValues.Name] = tostring(ColorValues.Color):split(", ")
			print(tostring(ColorValues.Color):split(", "))
		return colorsTable

local function save(player: Player)	
	local colorsaved = colortable(player)
	local success, errormessage = pcall(function()
		local PlayerUserId = 'Player_'.. player.UserId
		ColorStorage:SetAsync(PlayerUserId, colorsaved)

Players.PlayerAdded:Connect(function(player: Player)

Players.PlayerRemoving:Connect(function(player: Player)
		local Check = Players:GetPlayerFromCharacter(Character)

PlayerRemoving is not enough when it comes to datastores!
You need to also use BindToClose to make sure the last player who leaves the server has their data saved.

1 Like

well, that’s one of my problems solved. but what about when it comes to loading data, it’s not loading the values i want it to load (unless i’ve miss read what you said)

That would be because it didnt save the previous data wouldnt it?

Unless you mean loading them incorrectly in the wrong RGB order, in which case the problem is simple
you’re not loading them in the correct order;
try to not use unpack to enter the RGB values, use [1],[2],[3] instead to make sure its in the correct order

1 Like

it’s saving correctly it even saved the jetpack colors from the last time since i haven’t touched those values, i don’t know what it’s loading but it keeps loading the same old data. it doesn’t get overwritten, when i print out the load data it just shows the same old data, and the saved data is the right data i want. I’m trying to think what caused this issue since this started to have problems out of nowhere

try it with the bindtocloase, see if it saves and then loads the correct data

1 Like

yeah the bindtoclose made it work, just doing a few more test atm before i mark you for a solutions (alright everything is working thanks for the help) … ( yeah I’ve noticed there’s a bit of delay which was kinda annoying)

1 Like

personally i recommend checking if you’re in studio using RunService:IsStudio() for better quality of life (if you noticed using bindtoclose makes it wait a long time before actually ending the test session)