Data not saving after first save

So basically wouldn’t save after the first save. Here is my code:

local typ = game:GetService("DataStoreService")
local SaveClicks = typ:GetDataStore("SaveLeaderBoard")

players.PlayerAdded:Connect(function(plr)
	local Leaderboard  = Instance.new("Folder", plr)
	Leaderboard.Name = "leaderstats"

	local Clicks = Instance.new("IntValue", Leaderboard)
	Clicks.Name = "Clicks"

	local Rebirths = Instance.new("IntValue", Leaderboard)
	Rebirths.Name = "Rebirths"
	
	local SR
	local SC
	
	local success, err = pcall(function()
		SR = SaveClicks:GetAsync("SavedRebirths_"..plr.UserId)
		SC = SaveClicks:GetAsync("SavedClicks_"..plr.UserId)
	end)
	
	if success then
		if SC then
			Clicks.Value = SC
		end

		if SR then
			Rebirths.Value = SR
		end
	else
		warn(err)
	end
end)

players.PlayerRemoving:Connect(function(plr)
	local Clicks = plr.leaderstats.Clicks.Value
	local Rebirths = plr.leaderstats.Rebirths.Value
	
	
	local success, err = pcall(function()
		SaveClicks:SetAsync("SavedClicks_"..plr.UserId, Clicks)
		SaveClicks:SetAsync("SavedRebirths_"..plr.UserId, Rebirths)
	end)
	
	if success then
		print(table)
	else
		warn(err)
		warn("BRUHH")
	end
end)

Are you running this in studio or a live server?

I am running the test in studio so yeah.

Studio doesn’t always save data, it’ll work in a live server

2 Likes

Thank you man for telling me about my problem!