Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

My first script having debounce and it obviously don't work, help?

I'm trying to make it have cooldown, something wrong with my debounce...

local productId = script.Parent.Id.Value
local player = game.Players.LocalPlayer
debounce = false
if debounce == false then
script.Parent.MouseButton1Click:connect(function()
	game:GetService("MarketplaceService"):PromptProductPurchase(player, productId)
local MarketplaceService = game:GetService("MarketplaceService")    
MarketplaceService.ProcessReceipt = function(receiptInfo)	
	if receiptInfo.ProductId == productId then
while true do	
	for i = 600,0,-1 do
	script.Parent.Text = i
	wait(0.1)
	if i <= 0 then
		local h = Instance.new("Hint",workspace)
		h.Text = "Over!"
	end
	end
end
	debounce = true
	wait(600)
	end
end
end)
end
debounce = false

2 answers

The debounce is supposed to be run inside a function. In order for debounce to work, there has to be a wait time so that the function won't run again until that wait time is over.

Here's an example of what it should look like:

local Debounce = false

script.Parent.MouseButton1Down:Connect(function()
	if Debounce == false then
		Debounce = true
		print("Wait 3 seconds before this can be run again!")
		wait(3)
		Debounce = false
	end
end)

Hope this helps!

You forgot to add the "debounce = true" and the wait before the debounce = false

Beinning of debounce should look like this

debounce = false
if debounce == false then
debounce = true
script.Parent.MouseButton1Click:connect(function()

End of script will look like:

end
end)
end
wait(1)
--^Any number of your choice^
debounce = false

This discussion is preserved as it was. New answers, comments, and votes are closed.