DataStore isn't Saving Updated Table Values?

  1. What do you want to achieve?
    I want to save a table of IntValues that are in ReplicatedStorage and their values are changed through a ServerScript in ServerScriptService.

  2. What is the issue?
    The IntValues change, but it doesn’t seem to save the IntValues at all.
    (These IntValues act as BoolValues, I want them to either be 1 or 0).

Output Before Player Buys Upgrade
image

Output After Player Buys Upgrade

  1. What solutions have you tried so far?
    I made a previous topic that was similar, but it was about the values not being changed and updated. Right now, it is changing and updating but it isn’t saving.
    I also made a function to see if the values change, it is for sure 1.

ServerScript under two folders in ServerScriptService
(The Script is called ClassSaveScript)

local Upgrade1 = game.ReplicatedStorage.ClassFolder.ClassUpgrades.Juggernaut.UpgradeSave1
local Upgrade2 = game.ReplicatedStorage.ClassFolder.ClassUpgrades.Juggernaut.UpgradeSave2
local Upgrade3 = game.ReplicatedStorage.ClassFolder.ClassUpgrades.Juggernaut.UpgradeSave3
local Upgrade4 = game.ReplicatedStorage.ClassFolder.ClassUpgrades.Juggernaut.UpgradeSave4
local Upgrade5 = game.ReplicatedStorage.ClassFolder.ClassUpgrades.Juggernaut.UpgradeSave5
local Upgrade6 = game.ReplicatedStorage.ClassFolder.ClassUpgrades.Juggernaut.UpgradeSave6
local Upgrade7 = game.ReplicatedStorage.ClassFolder.ClassUpgrades.Juggernaut.UpgradeSave7
local Upgrade8 = game.ReplicatedStorage.ClassFolder.ClassUpgrades.Juggernaut.UpgradeSave8

game.Players.PlayerAdded:Connect(function()
	print(Upgrade1.Value.." That was da value he he heh eh eh ehe")
end)

Upgrade1.Changed:Connect(function()
	Upgrade1.Value = 1
	print("Upgrade 1 Value is "..Upgrade1.Value)
end)
Upgrade2.Changed:Connect(function()
	Upgrade2.Value = 1
end)
Upgrade3.Changed:Connect(function()
	Upgrade3.Value = 1
end)
Upgrade4.Changed:Connect(function()
	Upgrade4.Value = 1
end)
Upgrade5.Changed:Connect(function()
	Upgrade5.Value = 1
end)
Upgrade6.Changed:Connect(function()
	Upgrade6.Value = 1
end)
Upgrade7.Changed:Connect(function()
	Upgrade7.Value = 1
end)
Upgrade8.Changed:Connect(function()
	Upgrade8.Value = 1
end)

while task.wait(1) do
	print("Upgrade 1 Value is probably being updated here ".. Upgrade1.Value)
	local classTable = {Upgrade1.Value, Upgrade2.Value, Upgrade3.Value, Upgrade4.Value, Upgrade5.Value, Upgrade6.Value, Upgrade7.Value, Upgrade8.Value} -- This is the Table
end

--Data Store
local DataStoreService = game:GetService("DataStoreService")
local experienceStore = DataStoreService:GetDataStore("PlayerExperience")
local classStore = DataStoreService:GetDataStore("JuggernautStore")

local players = game:GetService("Players")

local function onShutDown()
	task.wait(3)
end

local function setUp(player)
	local userID = player.UserId
	local key = "Player_"..userID

	local data = classStore:GetAsync(key)
	local success, ret = pcall(classStore.GetAsync, classStore, key)

	if success then
		classTable = ret or 0
	else
		print("Uh oh there's an error man "..ret)
	end

	repeat
		local success, ret = pcall(classStore.GetAsync, classStore, key)
	until success or not players:FindFirstChild(players.Name)

	classTable = data or 0
end

local function save(player)
	local userID = player.UserId
	local key = "Player_"..userID
	
	wait(6)
	classStore:SetAsync(key, classTable)

	local success, ret = pcall(classStore.SetAsync, classStore, key)

	if success then
		print("Yippee! The Upgrade have been SAVED")
	else
		print("Uh oh there's an error man "..ret)
	end

	repeat
		local success, ret = pcall(classStore.SetAsync, classStore, key)
	until success or not players:FindFirstChild(players.Name)
end

while wait(60) do
	players.PlayerRemoving:Connect(save)
end

game:BindToClose(onShutDown)
players.PlayerAdded:Connect(setUp)
players.PlayerRemoving:Connect(save)

I also won’t be able to respond in a couple of hours because of some errands I have to run

Ignoring the fact this would merge data of all players into one profile which I imagine is non-desirable…

You don’t have any code to take the loaded data and place it into the IntValue values.
You’d need to do something like below within the setUp() function

Upgrade1.Value = data[1]
Upgrade2.Value = data[2]
Upgrade3.Value = data[3]
...

(this could be written more compact if the Upgrade IntValue references were stored in an array rather than declared as separate local variables)

Hey sorry for the late response. I don’t have to worry about merging data because my game is singleplayer, but would it look something like this? Or would I put it inside if the save succeeds? I’m new to saving data so I’m shooting in the dark with this one.
I also just tested it, and it doesn’t save. (Probably cause I put it in the wrong spot)

local function setUp(player)
	local userID = player.UserId
	local key = "Player_"..userID

	local data = classStore:GetAsync(key)
	local success, ret = pcall(classStore.GetAsync, classStore, key)
	
	Upgrade1.Value = data[1]
	Upgrade2.Value = data[2]
	Upgrade3.Value = data[3]
	Upgrade4.Value = data[4]
	Upgrade5.Value = data[5]
	Upgrade6.Value = data[6]
	Upgrade7.Value = data[7]
	Upgrade8.Value = data[8]
	
	if success then
		classTable = ret or 0
	else
		print("Uh oh there's an error man "..ret)
	end

	repeat
		local success, ret = pcall(classStore.GetAsync, classStore, key)
	until success or not players:FindFirstChild(players.Name)

	classTable = data or 0
end