Interest Rate (Banking System)

Hello there Devs! I wanted to make a Interest Rate Sytem which will give the playe interest…

local function giveInterest(player)
	local InterestRate = 0.02 
	while true do
		wait(10) 
		local leaderstats = player:FindFirstChild("leaderstats")
		if leaderstats then
			local currency = leaderstats:FindFirstChild("Coins")
			if currency then
				local currentBalance = currency.Value
				local interest = currentBalance * InterestRate
				currency.Value = currentBalance + interest
				print(player.Name .. " received interest: " .. interest)
			end
		end
	end
end

game.Players.PlayerAdded:Connect(function(player)
	giveInterest(player)
end)

What I need help in is that if a player leaves I still want the interest rate system to work and give the player coins that he earned while he was no in the game when he joins the next session

1 Like

Save a timestamp when the player left in the datastore, and and when they join compare previous timestamp with current timestamp to make the math to calculate how much they earned

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.