GUI vs Datastore

Hello, I have this problem with my script inside of a gui. Whenever I click on the gui, it adds 100k to my value which is then saved when I leave the game. However, when I rejoin, the value I had did not actually save and reverts back to the value before I clicked on the gui.

I’m pretty sure my datastore script is fine, but the gui instead.

Example:
Join → 0
Click on gui —> Value = 100k
Rejoin —> 0

local player = game.Players.LocalPlayer
local data1 = player:WaitForChild("Data1")
local data2 = player:WaitForChild("Data2")
local leaderstats = player:WaitForChild("leaderstats")
local pets = player:WaitForChild("Pets")

local UC = data1:WaitForChild("UncookedChiikens")
local Multiplier = data2:WaitForChild("Multiplier")
local CC = pets:WaitForChild("CommonChiiken")
local RC = pets:WaitForChild("RareChiiken")
local EC = pets:WaitForChild("EpicChiiken")

local Chiikens = leaderstats:WaitForChild("Chiikens")

local gui = script.Parent.Parent.Parent
local bg = gui.WarningBG
local notown = bg.NotOwn
local freebie = bg.Freebie

local debounce = false

script.Parent.MouseButton1Click:Connect(function()
	if CC.Value == true then
		if debounce == false then
			debounce = true
			UC.Value += 100000
			wait(5)
			debounce = false
			return
		end
	else
		if debounce == false then
			bg.Visible = true
			notown.Visible = true
			debounce = true
			wait(5)
			bg.Visible = false
			notown.Visible = false
			debounce = false
		end
	end
	if  CC.Value == true and RC.Value == true then
		if debounce == false then
			debounce = true
			UC.Value += 10100000
			wait(3) 
			debounce = false
			return
		end
	else
		if debounce == false then
			bg.Visible = true
			notown.Visible = true
			debounce = true
			wait(5)
			bg.Visible = false
			notown.Visible = false
			debounce = false
		end
	end
	
	if CC.Value == true and RC.Value == true and EC.Value == true then
		if debounce == false  then
			debounce = true
			UC.Value += 65100000
			Multiplier.Value += 25
			wait(15) 
			debounce = false
			return
		end
	else
		if debounce == false then
			bg.Visible = true
			notown.Visible = true
			debounce = true
			wait(5)
			bg.Visible = false
			notown.Visible = false
			debounce = false
		end
	end
end)


Are you just storing the data inside the player and expecting it to save? I see no indication of you getting the data store service unless you just didn’t include it in the code you provided. I’d watch a video on data stores if i were you

The script mentioned is the script in the gui. If you look in the code, I am getting folders that the datastore clones into the client. The folders being leaderstats , pets, data1 and data2. I don’t need to get datastore service because when the player leaves, the data saves not when the data is updated.

This is because the value is only changed on the client, not the server. This can be fixed by sending a remote event to change the value on the server.