Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
0msh 333 Moderation Voter
7 years ago

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

Log in to vote
1
Answered by
Mayk728 855 Moderation Voter
7 years ago

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!

Ad
Log in to vote
0
Answered by 7 years ago

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

Answer this question