How do i add a cooldown to proximity prompt

I made a script where you can beg for money. I want to be able to add a cooldown after you beg. and when you beg again while you are on a cooldown I would like it to show a special message, how do I do that
my script

function onTouched(player)
	math.randomseed(tick())
	local money = math.floor(math.random(5,10))
	local Chance = math.floor(math.random(1,10))
	if Chance <= 3 then
		for a,b in pairs(game.Players:GetPlayers())do
			if b:FindFirstChild'leaderstats'then
				b.leaderstats.Money.Value=b.leaderstats.Money.Value+money
				local PlayerGui = player:WaitForChild("PlayerGui")
				local ScreenGui = PlayerGui.TrashGui
				local Frame = ScreenGui.Found
				Frame.Visible = true
				Frame.TextLabel.Text = "The Noob gave you "..tostring(money).."$!"
				wait(3)
				Frame.Visible = false
			end
		end
	elseif Chance >= 4 then
		for a,b in pairs(game.Players:GetPlayers())do
			if b:FindFirstChild'leaderstats'then
				b.leaderstats.Reputation.Value=b.leaderstats.Reputation.Value-Chance
		local PlayerGui = player:WaitForChild("PlayerGui")
		local ScreenGui = PlayerGui.TrashGui
		local Frame = ScreenGui.Lost
				Frame.Visible = true
				Frame.TextLabel.Text = "Noob: Sorry I got no spare change"
		wait(3)
				Frame.Visible = false
			end
		end		
	end
end
script.Parent.Triggered:Connect(onTouched)

You could use a debounce. Here’s an example:

local debounce = false
function abc()
  if debounce == true then return end
  debounce = true
  -- do stuff
  wait(cooldown time)
  debounce = false
end
1 Like