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

How can I replace this with debounce?

Asked by 5 years ago
function BP()
    script.Parent.CFrame = script.Parent.CFrame * CFrame.new(-.06, 0, 0)
    script.Parent.ClickSound:Play()
    script.Parent.ClickDetector.MaxActivationDistance = 0
end
function BU()
    script.Parent.CFrame = script.Parent.CFrame * CFrame.new(.06, 0, 0)
    script.Parent.ClickDetector.MaxActivationDistance = 10
end
function onClicked()
    local a = math.random(1, 24)
    if a == 1 then
        BP()
        game.ReplicatedStorage.Coins:Clone().Parent = game.Workspace
        script.Parent.Sounds.Coinsound:Play()
        wait(3)
        BU()
    elseif a == 2 then
        BP()
        game.ReplicatedStorage.Doge:Clone().Parent = game.Workspace
        script.Parent.Sounds.Dogesong:Play()
        wait(12.669)
        BU()
    elseif a == 3 then
        BP()
        game.ReplicatedStorage.Jail:Clone().Parent = game.Workspace
        script.Parent.Sounds.Jailsound:Play()
        game.ReplicatedStorage.Jail2:Clone().Parent = game.Workspace
        wait(5)
        BU()
    elseif a == 4 then
        BP()
        script.Parent.Sounds.MoneyParticle:Play()
        game.ReplicatedStorage.MoneyParticle:Clone().Parent = game.Workspace
        wait(4.5)
        BU()
    elseif a == 5 then
        BP()
        script.Parent.Sounds.Dinner:Play()
        game.ReplicatedStorage.Dinner:Clone().Parent = game.Workspace
        wait(5)
        BU()
    elseif a == 6 then
        BP()
        game.ReplicatedStorage.Sign:Clone().Parent = game.Workspace
        script.Parent.Sounds.Sign:Play()
        wait(7)
        game.Workspace.Sign.Sound:Play()
        game.ReplicatedStorage.Explode:Clone().Parent = game.Workspace
        wait(2)
        BU()
    elseif a == 7 then
        BP()
        game.ReplicatedStorage.Laser:Clone().Parent = game.Workspace
        script.Parent.Sounds.Laser:Play()
        wait(3)
        BU()
    elseif a == 8 then
        BP()
        game.ReplicatedStorage.DarkMatter:Clone().Parent = game.Workspace
        wait(10)
        BU()
    elseif a == 9 then
        BP()
        game.ReplicatedStorage.Lava:Clone().Parent = game.Workspace
        wait(7)
        BU()
    elseif a == 10 then
        BP()
        game.ReplicatedStorage.Phonebooth:Clone().Parent = game.Workspace
        wait(10)
        BU()
    elseif a == 11 then
        BP()
        game.ReplicatedStorage.Rotating:Clone().Parent = game.Workspace
        wait(10)
        BU()
    elseif a == 12 then
        BP()
        game.ReplicatedStorage.PlatformStand:Clone().Parent = game.Workspace
        script.Parent.Sounds.Fall:Play()
        wait(5)
        BU()
    elseif a == 13 then
        BP()
        game.ReplicatedStorage.Fancy:Clone().Parent = game.Workspace
        script.Parent.Sounds.Fancy:Play()
        wait(10)
        script.Parent.Sounds.Fancy:Stop()
        BU()
    elseif a == 14 then
        BP()
        game.ReplicatedStorage.what:Clone().Parent = game.Workspace
        script.Parent.Sounds.what:Play()
        wait(2.808)
        BU()
    elseif a == 15 then
        BP()
        game.ReplicatedStorage.woah:Clone().Parent = game.Workspace
        game.ReplicatedStorage.woah2:Clone().Parent = game.Workspace
        script.Parent.Sounds.woah:Play()
        wait(10)
        script.Parent.Sounds.woah:Stop()
        BU()
    elseif a == 16 then
        BP()
        game.ReplicatedStorage.Toilet:Clone().Parent = game.Workspace
        script.Parent.Sounds.Plop:Play()
        wait(3)
        BU()
    elseif a == 17 then
        BP()
        script.Parent.Sounds.FUN:Play()
        wait(.5)
        script.Parent.Fire.Enabled = true
        wait(2)
        script.Parent.Fire.Enabled = false
        wait(1)
        game.ReplicatedStorage.Uranium:Clone().Parent = game.Workspace
        wait(2)
        game.ReplicatedStorage.Bombs:Clone().Parent = game.Workspace
        wait(2)
        game.ReplicatedStorage.Explode:Clone().Parent = game.Workspace
        BU()
    elseif a == 18 then
        BP()
        script.Parent.Sounds.Dance:Play()
        game.ReplicatedStorage.Dance:Clone().Parent = game.Workspace
        game.ReplicatedStorage.Dance2:Clone().Parent = game.Workspace
        wait(18)
        script.Parent.Sounds.Dance:Stop()
        BU()
    elseif a == 19 then
        BP()
        game.ReplicatedStorage.Record:Clone().Parent = game.Workspace
        wait(13)
        BU()
    elseif a == 20 then
        BP()
        game.ReplicatedStorage.Lava2:Clone().Parent = game.Workspace
        wait(5.9)
        BU()
    elseif a == 21 then
        BP()
        game.ReplicatedStorage.Piano:Clone().Parent = game.Workspace
        wait(10)
        BU()
    elseif a == 22 then
        BP()
        game.ReplicatedStorage.Diamonds:Clone().Parent = game.Workspace
        script.Parent.Sounds.Minecraft:Play()
        wait(7)
        game.ReplicatedStorage.Steve1:Clone().Parent = game.Workspace
        wait(5)
        game.ReplicatedStorage.Steve2:Clone().Parent = game.Workspace
        wait(8)
        game.ReplicatedStorage.Steve3:Clone().Parent = game.Workspace
        wait(2)
        game.ReplicatedStorage.Steve4:Clone().Parent = game.Workspace
        wait(5)
        script.Parent.Sounds.Minecraft:Stop()
        game.Workspace.Steve1:Destroy()
        game.Workspace.Diamonds:Destroy()
        game.Workspace.Steve2:Destroy()
        game.Workspace.Steve3:Destroy()
        game.Workspace.Steve4:Destroy()
        BU()
    elseif a == 23 then
        BP()
        game.ReplicatedStorage.Barry:Clone().Parent = game.Workspace
        script.Parent.Sounds.yalikejazz:Play()
        wait(3)
        script.Parent.Sounds.Jazz:Play()
        wait(10)
        game.Workspace.Barry:Destroy()
        script.Parent.Sounds.Jazz:Stop()
        BU()
    elseif a == 24 then
        BP()
        script.Parent.Sounds.Thomas:Play()
        wait(3)
        game.ReplicatedStorage.Thomas:Clone().Parent = game.Workspace
        wait(4.3)
        game.Workspace.Thomas:Destroy()
        script.Parent.Sounds.Thomas:Stop()
        BU()
    end
    end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

So basically if you look at the BP function then you can see that I make the MaxActivationDistance for the click detector 0. Then after a certain amount of time (depending on the outcome) the BU goes into play and reactivates the button essentially. This is my attempt to make it so the button isn't spam clicked. However this doesn't work all the time and I want to replace this system with debounce, however, I don't know how to and using debounce for every outcome would be very tedious. It is important to have the wait time be flexible so the debounce works for each outcome.

1 answer

Log in to vote
0
Answered by 5 years ago

Here is the db version!

db=false

function BP()
db=true
end

function BU()
db=false
end

function onClicked()
    if  db==false then
    local a = math.random(1, 24)
    if a == 1 then
        BP()
        game.ReplicatedStorage.Coins:Clone().Parent = game.Workspace
        script.Parent.Sounds.Coinsound:Play()
        wait(3)
        BU()
    elseif a == 2 then
        BP()
        game.ReplicatedStorage.Doge:Clone().Parent = game.Workspace
        script.Parent.Sounds.Dogesong:Play()
        wait(12.669)
        BU()
    elseif a == 3 then
        BP()
        game.ReplicatedStorage.Jail:Clone().Parent = game.Workspace
        script.Parent.Sounds.Jailsound:Play()
        game.ReplicatedStorage.Jail2:Clone().Parent = game.Workspace
        wait(5)
        BU()
    elseif a == 4 then
        BP()
        script.Parent.Sounds.MoneyParticle:Play()
        game.ReplicatedStorage.MoneyParticle:Clone().Parent = game.Workspace
        wait(4.5)
        BU()
    elseif a == 5 then
        BP()
        script.Parent.Sounds.Dinner:Play()
        game.ReplicatedStorage.Dinner:Clone().Parent = game.Workspace
        wait(5)
        BU()
    elseif a == 6 then
        BP()
        game.ReplicatedStorage.Sign:Clone().Parent = game.Workspace
        script.Parent.Sounds.Sign:Play()
        wait(7)
        game.Workspace.Sign.Sound:Play()
        game.ReplicatedStorage.Explode:Clone().Parent = game.Workspace
        wait(2)
        BU()
    elseif a == 7 then
        BP()
        game.ReplicatedStorage.Laser:Clone().Parent = game.Workspace
        script.Parent.Sounds.Laser:Play()
        wait(3)
        BU()
    elseif a == 8 then
        BP()
        game.ReplicatedStorage.DarkMatter:Clone().Parent = game.Workspace
        wait(10)
        BU()
    elseif a == 9 then
        BP()
        game.ReplicatedStorage.Lava:Clone().Parent = game.Workspace
        wait(7)
        BU()
    elseif a == 10 then
        BP()
        game.ReplicatedStorage.Phonebooth:Clone().Parent = game.Workspace
        wait(10)
        BU()
    elseif a == 11 then
        BP()
        game.ReplicatedStorage.Rotating:Clone().Parent = game.Workspace
        wait(10)
        BU()
    elseif a == 12 then
        BP()
        game.ReplicatedStorage.PlatformStand:Clone().Parent = game.Workspace
        script.Parent.Sounds.Fall:Play()
        wait(5)
        BU()
    elseif a == 13 then
        BP()
        game.ReplicatedStorage.Fancy:Clone().Parent = game.Workspace
        script.Parent.Sounds.Fancy:Play()
        wait(10)
        script.Parent.Sounds.Fancy:Stop()
        BU()
    elseif a == 14 then
        BP()
        game.ReplicatedStorage.what:Clone().Parent = game.Workspace
        script.Parent.Sounds.what:Play()
        wait(2.808)
        BU()
    elseif a == 15 then
        BP()
        game.ReplicatedStorage.woah:Clone().Parent = game.Workspace
        game.ReplicatedStorage.woah2:Clone().Parent = game.Workspace
        script.Parent.Sounds.woah:Play()
        wait(10)
        script.Parent.Sounds.woah:Stop()
        BU()
    elseif a == 16 then
        BP()
        game.ReplicatedStorage.Toilet:Clone().Parent = game.Workspace
        script.Parent.Sounds.Plop:Play()
        wait(3)
        BU()
    elseif a == 17 then
        BP()
        script.Parent.Sounds.FUN:Play()
        wait(.5)
        script.Parent.Fire.Enabled = true
        wait(2)
        script.Parent.Fire.Enabled = false
        wait(1)
        game.ReplicatedStorage.Uranium:Clone().Parent = game.Workspace
        wait(2)
        game.ReplicatedStorage.Bombs:Clone().Parent = game.Workspace
        wait(2)
        game.ReplicatedStorage.Explode:Clone().Parent = game.Workspace
        BU()
    elseif a == 18 then
        BP()
        script.Parent.Sounds.Dance:Play()
        game.ReplicatedStorage.Dance:Clone().Parent = game.Workspace
        game.ReplicatedStorage.Dance2:Clone().Parent = game.Workspace
        wait(18)
        script.Parent.Sounds.Dance:Stop()
        BU()
    elseif a == 19 then
        BP()
        game.ReplicatedStorage.Record:Clone().Parent = game.Workspace
        wait(13)
        BU()
    elseif a == 20 then
        BP()
        game.ReplicatedStorage.Lava2:Clone().Parent = game.Workspace
        wait(5.9)
        BU()
    elseif a == 21 then
        BP()
        game.ReplicatedStorage.Piano:Clone().Parent = game.Workspace
        wait(10)
        BU()
    elseif a == 22 then
        BP()
        game.ReplicatedStorage.Diamonds:Clone().Parent = game.Workspace
        script.Parent.Sounds.Minecraft:Play()
        wait(7)
        game.ReplicatedStorage.Steve1:Clone().Parent = game.Workspace
        wait(5)
        game.ReplicatedStorage.Steve2:Clone().Parent = game.Workspace
        wait(8)
        game.ReplicatedStorage.Steve3:Clone().Parent = game.Workspace
        wait(2)
        game.ReplicatedStorage.Steve4:Clone().Parent = game.Workspace
        wait(5)
        script.Parent.Sounds.Minecraft:Stop()
        game.Workspace.Steve1:Destroy()
        game.Workspace.Diamonds:Destroy()
        game.Workspace.Steve2:Destroy()
        game.Workspace.Steve3:Destroy()
        game.Workspace.Steve4:Destroy()
        BU()
    elseif a == 23 then
        BP()
        game.ReplicatedStorage.Barry:Clone().Parent = game.Workspace
        script.Parent.Sounds.yalikejazz:Play()
        wait(3)
        script.Parent.Sounds.Jazz:Play()
        wait(10)
        game.Workspace.Barry:Destroy()
        script.Parent.Sounds.Jazz:Stop()
        BU()
    elseif a == 24 then
        BP()
        script.Parent.Sounds.Thomas:Play()
        wait(3)
        game.ReplicatedStorage.Thomas:Clone().Parent = game.Workspace
        wait(4.3)
        game.Workspace.Thomas:Destroy()
        script.Parent.Sounds.Thomas:Stop()
        BU()
    end
    end
    end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

Hope this helped. <3

Ad

Answer this question