Why is my leaderstats giving me 2,500 clicks

This is the script

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

game.Players.PlayerAdded:Connect(function(Player)
	local Leaderstats = Instance.new("Folder")
	Leaderstats.Name = "leaderstats"
	Leaderstats.Parent = Player

	local clicks = Instance.new("IntValue")
	clicks.Name = "Clicks"
	clicks.Parent = Leaderstats

	local coins = Instance.new("IntValue")
	coins.Name = "Coins"
	coins.Parent = Leaderstats

	local rebirths = Instance.new("IntValue")
	rebirths.Name = "Rebirths"
	rebirths.Parent = Leaderstats

	local gems = Instance.new("IntValue")
	gems.Name = "Gems"
	gems.Parent = Leaderstats


	local clicksData
	local coinsData
	local rebirthsData
	local gemsData

	local Success, ErrorMessage = pcall(function()
		clicksData = DataStore:GetAsync(Player.UserId.."-clicksData")
		coinsData = DataStore:GetAsync(Player.UserId.."-coinsData")
		rebirthsData = DataStore:GetAsync(Player.UserId.."-rebirthsData")
		gemsData = DataStore:GetAsync(Player.UserId.."-gemsData")
	end)

	if not Success then
		print(ErrorMessage)
	end

	if clicksData ~= nil then
		clicks.Value = clicksData
	else
		clicks.Value = 10
	end

	if coinsData ~= nil then
		coins.Value = coinsData
	else
		coins.Value = 100
	end

	if rebirthsData ~= nil then
		rebirths.Value = rebirthsData
	else
		rebirths.Value = 0
	end

	if gemsData ~= nil then
		gems.Value = gemsData
	else
		gems.Value = 0
	end
end)

game.Players.PlayerRemoving:Connect(function(Player)
	pcall(function()
		DataStore:SetAsync(Player.UserId.."-clicksData", Player.leaderstats.clicks.Value)
		DataStore:SetAsync(Player.UserId.."-PointsData", Player.leaderstats.coins.Value)
		DataStore:SetAsync(Player.UserId.."-PointsData", Player.leaderstats.rebirths.Value)
		DataStore:SetAsync(Player.UserId.."-PointsData", Player.leaderstats.gems.Value)
	end)
end)

That is really weird, Ive just tried your code and it seems to be working, the only thing is maybe you added your clicks and it saved.

1 Like

ohh ya
:smile: :grinning: :smiley: :thinking: :smile: