How would I prevent this event from being spammed?

I have an allowance script but its so easily exploitable. It can just be spammed. I tried a debounce but that wont work. I dont really understand how to use tick.
heres what I got

local debounce = false
game.ReplicatedStorage.GiveAllowance.OnServerEvent:Connect(function(Player)
	
	local id = 59790671

	if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(Player.UserId,id) then
		
		if debounce == false then
			debounce = true
			Player.leaderstats.Cash.Value = Player.leaderstats.Cash.Value + 269
			wait(12)
			debounce = false
		end
		
	end
	
end)

You could try this:

local playerDebounces = {}
game.ReplicatedStorage.GiveAllowance.OnServerEvent:Connect(function(Player)
	local id = 59790671
	if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(Player.UserId,id) then
		if playerDebounces[Player.Name] == true then return end
		playerDebounces[Player.Name] = true

		Player.leaderstats.Cash.Value = Player.leaderstats.Cash.Value + 269
		delay(12,function()
			playerDebounces[Player.Name] = nil
		end)
	end
end)
1 Like