--[ FUNCTIONS ]--


game.Players.PlayerAdded:Connect(function(Player)
	

	--[{ LEADERSTATS }]--

    local Leaderstats = Instance.new("Folder")
    Leaderstats.Name = "leaderstats"
	Leaderstats.Parent = Player
	
	local Minutes = Instance.new("IntValue")
	Minutes.Name = "Minutes" -- changing name here (points, levels, time, etc.)
	Minutes.Value = 0 -- default value
	Minutes.Parent = Leaderstats
	
	local Cash = Instance.new("IntValue")
	Cash.Name = "Cash" -- changing name here (points, levels, time, etc.)
	Cash.Value = 0 -- default value
	Cash.Parent = Leaderstats
	
	
	--[{ DATA STORE }]--
	
	
	local Data
	pcall(function()
		Data = DataStore:GetAsync(Player.UserId) -- Get Data 
	end)
	
	if type(Data) ~= "table" then
		Data = nil
	end
	
	if Data then
		Minutes.Value = Data.Minutes
		Cash.Value = Data.Cash
	end
	
	local incrementValue = 1 -- value when adding points

	if (service:UserOwnsGamePassAsync(Player.UserId, VIPGamepassId)) then -- 3x gamepass
		incrementValue = 3
	elseif (service:UserOwnsGamePassAsync(Player.UserId, GamepassId)) then -- 2x gamepass
		incrementValue = 2
	end
	

	--[{ TIME GIVERS }]--
	
	
	coroutine.resume(coroutine.create(function() -- gives 1 point every minute
		while true do
			wait(60) -- every minute
			Minutes.Value = Minutes.Value + incrementValue --  adds points based off of the incrementValue
		end
	end))
	
	coroutine.resume(coroutine.create(function() -- gives 1 point every minute
		while true do
			wait(120) -- every 2 minutes
			Cash.Value = Cash.Value + incrementValue -- adds cash
		end
	end))
	
	
end)




game.Players.PlayerRemoving:Connect(function(Player) -- save function here
	
	--[{ DATA STORE SAVING }]--
	
	DataStore:SetAsync(Player.UserId, { -- gets data
		Minutes = Player.leaderstats.Minutes.Value,
		Cash = Player.leaderstats.Cash.Value
	})
	
end)
