How do I add a debounce to this script?

  1. What do you want to achieve?

I want to achieve a good debounce.

  1. What is the issue?

They issue is its not efficient!

  1. What solutions have you tried so far?

Finding a solution!

local db = true

script.Redboxingglove.OnServerEvent:Connect(function(player)
	if db == true then
		db = false

		task.wait(0.4)
		db = true
		if player.leaderstats.Strength.Value >= player.BackpackShop.Capacity.Value then
			player.leaderstats.Strength.Value = player.BackpackShop.Capacity.Value

		else
			player.Level.Exp.Value = player.Level.Exp.Value + 1
			player.leaderstats.Strength.Value = player.leaderstats.Strength.Value + 1 * getMultiplier(player, "Multiplier2") * player.RankMultiplier.Value
			if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId,id) then
				player.leaderstats.Strength.Value = player.leaderstats.Strength.Value + 1 * getMultiplier(player, "Multiplier2") * 1 * player.RankMultiplier.Value
			end
		end
	end
end)

Thank you in advance!

Basic example of debounces

local debounce = false
if not deboucne then
    debounce = true
    task.wait(.4)
    debounce = false
end