--[[
local dataStore = game:GetService("DataStoreService") -- gets the data store service
local data = dataStore:GetDataStore("Stats") -- makes a new data stored named "stats"


game.Players.PlayerAdded:Connect(function(plr) -- when a player joins the game

	local leaderstats = Instance.new("Folder") -- we make a leaderstats that will hold the visible stats of a player
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = plr

	local Clicks = Instance.new("NumberValue") -- we make a stat named coins, you can name it whatever you want
	Clicks.Name = "Clicks"
	Clicks.Parent = leaderstats


	local Rebirths = Instance.new("NumberValue")  -- we make a second stat named xp, you can also name it whatever you want instead
	Rebirths.Name = "Rebirths"
	Rebirths.Parent = leaderstats


	local Gems = Instance.new("NumberValue")  -- we make a second stat named xp, you can also name it whatever you want instead
	Gems.Name = "Gems"
	Gems.Parent = leaderstats
	
	
	local Clicks
	local Rebirths
	local Gems



	Clicks = data:GetAsync(plr.UserId.."-Clicks") 
	-- ^^ we see if the the coin stat has been saved in the players key (their user ID) and we save coins in the "Coins" data key so we know we know we are saving coins

	Rebirths =  data:GetAsync(plr.UserId.."-Rebirths")-- same as the top except its with the xp stat
	
	Gems =  data:GetAsync(plr.UserId.."-Gems")-- same as the top except its with the xp stat
	

	if Clicks ~= nil then -- if the player has coins saved (more than 0)

		plr.leaderstats.Clicks.Value = Clicks

	end


	if Rebirths ~= nil then  -- if the player has xp saved (more than 0)

		plr.leaderstats.Rebirths.Value = Rebirths

	end


	if Gems ~= nil then  -- if the player has xp saved (more than 0)

		plr.leaderstats.Gems.Value = Gems

	end
end)

game.Players.PlayerRemoving:Connect(function(plr) -- when the players leave


	local sucess, errormsg = pcall(function() -- pcall function helps the script to contain the error if there is one instead of breaking the entire script


		data:SetAsync(plr.UserId.."-Clicks", plr.leaderstats.Clicks.Value) -- the players stats will be set to the players sync for coins

		data:SetAsync(plr.UserId.."-Rebirths", plr.leaderstats.Rebirths.Value) --  same thing but with the xp stat
		
		data:SetAsync(plr.UserId.."-Gems", plr.leaderstats.Gems.Value) --  same thing but with the xp stat
		

	end)

	if errormsg then -- if theres an error with the data store

		warn("error")
	end

end)

--]]