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

How to make a button only do 1 disaster if it's clicked 2 or more times?

Asked by 5 years ago
Edited 5 years ago

I'm making a sequel to don't press the button. It's released but if you press the button at the same time or 2 or more times it makes the disasters glitch and people mess with it and messes up. The button uses a clickdetector. Here's the button's main script :

-- Programmed by Skylark011
local db = true
script.Parent.ClickDetector.MouseClick:connect(function(Player)
    print("click")
    game.Workspace.lobby:Stop()
    print("GLOBAL SSEQ STOP")
    local parts = game.ServerStorage
    script.Parent.BrickColor = BrickColor.Red()
    script.Parent.clicksound:Play()
    script.Parent.ClickDetector.MaxActivationDistance = "0"
    print("math.random is running...")
    print("CHOOSING DISASTER")
    local m = math.random(1, 11)
    if m == 1 then 
        if db then
        db = false
        print("math.random choosed 1.")
        print("OH NOES TEH TORNADO IS COMIN")
        parts.Tornado:Clone().Parent = game.Workspace
        wait(25)
        game.Workspace.Tornado:Destroy()
        script.Parent.ClickDetector.MaxActivationDistance = "32"
        script.Parent.BrickColor = BrickColor.Green()
        game.Workspace.lobby:Play()
        game.Lighting.Brightness = 2
        print("GLOBAL SSEQ START")
        wait()
        db = true
        end
    end
    if m == 2 then
        if db then
        db = false
        print("math.random choosed 2.")
        print("AHHH METEOR! PRESSURE IS ON NOW!")
        parts.meteorattack:Clone().Parent = game.Workspace
        wait(30)
        game.Workspace.meteorattack:Destroy()
        script.Parent.ClickDetector.MaxActivationDistance = "32"
        script.Parent.BrickColor = BrickColor.Green()
        game.Workspace.lobby:Play()
        print("GLOBAL SSEQ START")
        wait()
        db = true
        end
    end
    if m == 3 then 
        if db then
        db = false
        print("math.random choosed 3.")
        print("IMA FIRIN MAH LAZER!!")
        parts.lazar:Clone().Parent = game.Workspace
        wait(4)
        game.Workspace.lazar:Destroy()
        game.Workspace.blast:Destroy()
        script.Parent.ClickDetector.MaxActivationDistance = "32"
        script.Parent.BrickColor = BrickColor.Green()
        game.Workspace.lobby:Play()
        print("GLOBAL SSEQ START")
        wait()
        db = true
        end
    end
    if m == 4 then 
        if db then
        db = false
        print("math.random choosed 4.")
        print("obby time!! :DDDD")
        game.Workspace.block1.CanCollide = false
        parts.obby:Clone().Parent = game.Workspace
        wait(60)
        game.Workspace.obby:Destroy()
        script.Parent.ClickDetector.MaxActivationDistance = "32"
        script.Parent.BrickColor = BrickColor.Green()
        game.Workspace.block1.CanCollide = true
        game.Workspace.lobby:Play()
        print("GLOBAL SSEQ START")
        wait()
        db = true
        end
    end
    if m == 5 then 
    if db then
        db = false
        print("math.random choosed 5.")
        print("skylark has a present!")
        parts.sky:Clone().Parent = game.Workspace
        wait(15)
        script.Parent.ClickDetector.MaxActivationDistance = "32"
        script.Parent.BrickColor = BrickColor.Green()
        game.Workspace.lobby:Play()
        print("GLOBAL SSEQ START")
        wait()
        db = true
        end
    end
   if m == 6 then 
    if db then
        db = false
        print("math.random choosed 6.")
        print("RIP IDK")
        parts.zombieattack:Clone().Parent = game.Workspace
        wait(35)
        game.Workspace.zombieattack:Destroy()
        game.Workspace.Zombie:Destroy()
        script.Parent.ClickDetector.MaxActivationDistance = "32"
        script.Parent.BrickColor = BrickColor.Green()
        game.Workspace.lobby:Play()
        game.Lighting.Brightness = 2
        print("GLOBAL SSEQ START")
        wait()
        db = true
        end
     end
     if m == 7 then
    if db then
        db = false
        print("math.random choosed 7.")
        print("noob song!!!111")
        parts.dancing:Clone().Parent = game.Workspace
        wait(38.2)
        game.Workspace.dancing:Destroy()
        game.Workspace.noob:Stop()
        game.Workspace.Disco_Light.Disabled = true
        game.Lighting.Ambient = Color3.new(0,0,0)
        script.Parent.ClickDetector.MaxActivationDistance = "32"
        script.Parent.BrickColor = BrickColor.Green()
        game.Workspace.lobby:Play()
        print("GLOBAL SSEQ START")
        wait()
        db = true
        end
     end
     if m == 8 then 
    if db then
        db = false
        print("math.random choosed 8.")
        print("A FLOOD!! GRRGHGRGHG")
        parts.flood:Clone().Parent = game.Workspace
        wait(30)
        game.Workspace.flood:Destroy()
        script.Parent.ClickDetector.MaxActivationDistance = "32"
        script.Parent.BrickColor = BrickColor.Green()
        game.Workspace.lobby:Play()
        print("GLOBAL SSEQ START")
        wait()
        db = true
        end
end
if m == 9 then 
    if db then
        db = false
        print("math.random choosed 9.")
        print("jumprope time!!!!")
        game.Workspace.block1.CanCollide = false
        game.Workspace.block2.CanCollide = false
        game.Workspace.block3.CanCollide = false
        game.Workspace.block4.CanCollide = false
        script.Parent.Parent.Part1.CanCollide = false
        script.Parent.Parent.Part2.CanCollide = false
        script.Parent.Parent.Part3.CanCollide = false
        script.Parent.Parent.click.CanCollide = false
        parts.jumper:Clone().Parent = game.Workspace
        wait(40)
        game.Workspace.jumper:Destroy()
        script.Parent.Parent.Part1.CanCollide = true
        script.Parent.Parent.Part2.CanCollide = true
        script.Parent.Parent.Part3.CanCollide = true
        script.Parent.Parent.click.CanCollide = true
        game.Workspace.block1.CanCollide = true
        game.Workspace.block2.CanCollide = true
        game.Workspace.block3.CanCollide = true
        game.Workspace.block4.CanCollide = true
        script.Parent.ClickDetector.MaxActivationDistance = "32"
        script.Parent.BrickColor = BrickColor.Green()
        game.Workspace.lobby:Play()
        print("GLOBAL SSEQ START")
        wait()
        db = true
        end
end
if m == 10 then 
    if db then
        db = false
        print("math.random choosed 10.")
        print("O NOES IM FALLIN FOREVER")
        parts.fall:Clone().Parent = game.Workspace
        game.Workspace.Baseplate.CanCollide = false
        game.Workspace.Baseplate.Transparency = 1
        wait(10)
        game.Workspace.fall:Destroy()
        game.Workspace.Baseplate.CanCollide = true
        game.Workspace.Baseplate.Transparency = 0
        script.Parent.ClickDetector.MaxActivationDistance = "32"
        script.Parent.BrickColor = BrickColor.Green()
        game.Workspace.lobby:Play()
        print("GLOBAL SSEQ START")
        wait()
        db = true
        end
     end
if m == 11 then 
    if db then
        db = false
        print("math.random choosed 11.")
        print("O NOES IM FALLIN FOREVER")
        parts["Purple Nebula"]:Clone().Parent = game.Lighting
        game.Workspace.worldy:Play()
        game.Workspace.Gravity = 22.2
        game.Workspace.Baseplate.Transparency = 1
        wait(30)
        game.Lighting["Purple Nebula"]:Destroy()
        game.Workspace.worldy:Stop()
        game.Workspace.Baseplate.Transparency = 0
        game.Workspace.Gravity = 196.2
        script.Parent.ClickDetector.MaxActivationDistance = "32"
        script.Parent.BrickColor = BrickColor.Green()
        game.Workspace.lobby:Play()
        print("GLOBAL SSEQ START")
        wait()
        db = true
        end
end
end)

So that's the main script. I don't know what to use. I've looked on the internet but I saw nothing. Please help! Thank you Its fixed!!

0
I have edited my answer giving you the solution that you can copy and paste. SteamG00B 1633 — 5y
0
I defaulted with wait(10) as you didn't provide any other requirements for activating the button again SteamG00B 1633 — 5y

2 answers

Log in to vote
0
Answered by
SteamG00B 1633 Moderation Voter
5 years ago
Edited 5 years ago

What you need is a debounce, it's really simple, it doesn't let anything happen if someone presses the button more than once before you allow it.

local db = true
script.Parent.ClickDetector.MouseClick:connect(function(Player)
    if db then
        db=false
        --your stuff
        if you allow a new disaster then 
            db=true
        end
    end
end)

you can either use the if you allow disaster then if statement, or you can just wait a certain amount of time.

--after your stuff
wait(10) --waits 10 seconds instead
db= true

If you had done exactly what I said to do, it would've looked like this:

local db = true
script.Parent.ClickDetector.MouseClick:connect(function(Player)
    if db then
    db = false
    print("click")
    game.Workspace.lobby:Stop()
    print("GLOBAL SSEQ STOP")
    local parts = game.ServerStorage
    script.Parent.BrickColor = BrickColor.Red()
    script.Parent.clicksound:Play()
    script.Parent.ClickDetector.MaxActivationDistance = "0"
    print("math.random is running...")
    print("CHOOSING DISASTER")
    local m = math.random(1, 11)
    if m == 1 then 
        print("math.random choosed 1.")
        print("OH NOES TEH TORNADO IS COMIN")
        parts.Tornado:Clone().Parent = game.Workspace
        wait(25)
        game.Workspace.Tornado:Destroy()
        script.Parent.ClickDetector.MaxActivationDistance = "32"
        script.Parent.BrickColor = BrickColor.Green()
        game.Workspace.lobby:Play()
        game.Lighting.Brightness = 2
        print("GLOBAL SSEQ START")
    end
    if m == 2 then 
        print("math.random choosed 2.")
        print("AHHH METEOR! PRESSURE IS ON NOW!")
        parts.meteorattack:Clone().Parent = game.Workspace
        wait(30)
        game.Workspace.meteorattack:Destroy()
        script.Parent.ClickDetector.MaxActivationDistance = "32"
        script.Parent.BrickColor = BrickColor.Green()
        game.Workspace.lobby:Play()
        print("GLOBAL SSEQ START")
    end
    if m == 3 then 
        print("math.random choosed 3.")
        print("IMA FIRIN MAH LAZER!!")
        parts.lazar:Clone().Parent = game.Workspace
        wait(4)
        game.Workspace.lazar:Destroy()
        game.Workspace.blast:Destroy()
        script.Parent.ClickDetector.MaxActivationDistance = "32"
        script.Parent.BrickColor = BrickColor.Green()
        game.Workspace.lobby:Play()
        print("GLOBAL SSEQ START")
    end
    if m == 4 then 
        print("math.random choosed 4.")
        print("obby time!! :DDDD")
        game.Workspace.block1.CanCollide = false
        parts.obby:Clone().Parent = game.Workspace
        wait(60)
        game.Workspace.obby:Destroy()
        script.Parent.ClickDetector.MaxActivationDistance = "32"
        script.Parent.BrickColor = BrickColor.Green()
        game.Workspace.block1.CanCollide = true
        game.Workspace.lobby:Play()
        print("GLOBAL SSEQ START")
    end
    if m == 5 then 
        print("math.random choosed 5.")
        print("skylark has a present!")
        parts.sky:Clone().Parent = game.Workspace
        wait(15)
        script.Parent.ClickDetector.MaxActivationDistance = "32"
        script.Parent.BrickColor = BrickColor.Green()
        game.Workspace.lobby:Play()
        print("GLOBAL SSEQ START")
    end
   if m == 6 then 
        print("math.random choosed 6.")
        print("RIP IDK")
        parts.zombieattack:Clone().Parent = game.Workspace
        wait(35)
        game.Workspace.zombieattack:Destroy()
        game.Workspace.Zombie:Destroy()
        script.Parent.ClickDetector.MaxActivationDistance = "32"
        script.Parent.BrickColor = BrickColor.Green()
        game.Workspace.lobby:Play()
        game.Lighting.Brightness = 2
        print("GLOBAL SSEQ START")
     end
     if m == 7 then 
        print("math.random choosed 7.")
        print("noob song!!!111")
        parts.dancing:Clone().Parent = game.Workspace
        wait(38.2)
        game.Workspace.dancing:Destroy()
        game.Workspace.noob:Stop()
        game.Workspace.Disco_Light.Disabled = true
        game.Lighting.Ambient = Color3.new(0,0,0)
        script.Parent.ClickDetector.MaxActivationDistance = "32"
        script.Parent.BrickColor = BrickColor.Green()
        game.Workspace.lobby:Play()
        print("GLOBAL SSEQ START")
     end
     if m == 8 then 
        print("math.random choosed 8.")
        print("A FLOOD!! GRRGHGRGHG")
        parts.flood:Clone().Parent = game.Workspace
        wait(30)
        game.Workspace.flood:Destroy()
        script.Parent.ClickDetector.MaxActivationDistance = "32"
        script.Parent.BrickColor = BrickColor.Green()
        game.Workspace.lobby:Play()
        print("GLOBAL SSEQ START")
end
if m == 9 then 
        print("math.random choosed 9.")
        print("jumprope time!!!!")
        game.Workspace.block1.CanCollide = false
        game.Workspace.block2.CanCollide = false
        game.Workspace.block3.CanCollide = false
        game.Workspace.block4.CanCollide = false
        script.Parent.Parent.Part1.CanCollide = false
        script.Parent.Parent.Part2.CanCollide = false
        script.Parent.Parent.Part3.CanCollide = false
        script.Parent.Parent.click.CanCollide = false
        parts.jumper:Clone().Parent = game.Workspace
        wait(40)
        game.Workspace.jumper:Destroy()
        script.Parent.Parent.Part1.CanCollide = true
        script.Parent.Parent.Part2.CanCollide = true
        script.Parent.Parent.Part3.CanCollide = true
        script.Parent.Parent.click.CanCollide = true
        game.Workspace.block1.CanCollide = true
        game.Workspace.block2.CanCollide = true
        game.Workspace.block3.CanCollide = true
        game.Workspace.block4.CanCollide = true
        script.Parent.ClickDetector.MaxActivationDistance = "32"
        script.Parent.BrickColor = BrickColor.Green()
        game.Workspace.lobby:Play()
        print("GLOBAL SSEQ START")
end
if m == 10 then 
        print("math.random choosed 10.")
        print("O NOES IM FALLIN FOREVER")
        parts.fall:Clone().Parent = game.Workspace
        game.Workspace.Baseplate.CanCollide = false
        game.Workspace.Baseplate.Transparency = 1
        wait(10)
        game.Workspace.fall:Destroy()
        game.Workspace.Baseplate.CanCollide = true
        game.Workspace.Baseplate.Transparency = 0
        script.Parent.ClickDetector.MaxActivationDistance = "32"
        script.Parent.BrickColor = BrickColor.Green()
        game.Workspace.lobby:Play()
        print("GLOBAL SSEQ START")
     end
if m == 11 then 
        print("math.random choosed 11.")
        print("O NOES IM FALLIN FOREVER")
        parts["Purple Nebula"]:Clone().Parent = game.Lighting
        game.Workspace.worldy:Play()
        game.Workspace.Gravity = 22.2
        game.Workspace.Baseplate.Transparency = 1
        wait(30)
        game.Lighting["Purple Nebula"]:Destroy()
        game.Workspace.worldy:Stop()
        game.Workspace.Baseplate.Transparency = 0
        game.Workspace.Gravity = 196.2
        script.Parent.ClickDetector.MaxActivationDistance = "32"
        script.Parent.BrickColor = BrickColor.Green()
        game.Workspace.lobby:Play()
        print("GLOBAL SSEQ START")
     end
     wait(10)
     db = true
end)

0
doesn't work. now the script is confused. ImSky_RBLX 2 — 5y
0
Can I see your implementation? Just edit your question and paste the new script below your original SteamG00B 1633 — 5y
0
wait nvm ImSky_RBLX 2 — 5y
0
So it works? SteamG00B 1633 — 5y
View all comments (2 more)
0
no it doesn't work. ImSky_RBLX 2 — 5y
0
Ok then edit your question so I can see what you changed SteamG00B 1633 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

Attempt :

-- Programmed by Skylark011
local db = false
script.Parent.ClickDetector.MouseClick:connect(function(Player)
    print("click")
    game.Workspace.lobby:Stop()
    print("GLOBAL SSEQ STOP")
    local parts = game.ServerStorage
    script.Parent.BrickColor = BrickColor.Red()
    script.Parent.clicksound:Play()
    script.Parent.ClickDetector.MaxActivationDistance = "0"
    print("math.random is running...")
    print("CHOOSING DISASTER")
    local m = math.random(1, 11)
    if m == 1 then 
        if db then
        db = true
        print("math.random choosed 1.")
        print("OH NOES TEH TORNADO IS COMIN")
        parts.Tornado:Clone().Parent = game.Workspace
        wait(25)
        game.Workspace.Tornado:Destroy()
        script.Parent.ClickDetector.MaxActivationDistance = "32"
        script.Parent.BrickColor = BrickColor.Green()
        game.Workspace.lobby:Play()
        game.Lighting.Brightness = 2
        print("GLOBAL SSEQ START")
        wait(10)
        db = false
        end
    end
    if m == 2 then
        if db then
        db = true
        print("math.random choosed 2.")
        print("AHHH METEOR! PRESSURE IS ON NOW!")
        parts.meteorattack:Clone().Parent = game.Workspace
        wait(30)
        game.Workspace.meteorattack:Destroy()
        script.Parent.ClickDetector.MaxActivationDistance = "32"
        script.Parent.BrickColor = BrickColor.Green()
        game.Workspace.lobby:Play()
        print("GLOBAL SSEQ START")
        wait(10)
        db = false
        end
    end
    if m == 3 then 
        if db then
        db = true
        print("math.random choosed 3.")
        print("IMA FIRIN MAH LAZER!!")
        parts.lazar:Clone().Parent = game.Workspace
        wait(4)
        game.Workspace.lazar:Destroy()
        game.Workspace.blast:Destroy()
        script.Parent.ClickDetector.MaxActivationDistance = "32"
        script.Parent.BrickColor = BrickColor.Green()
        game.Workspace.lobby:Play()
        print("GLOBAL SSEQ START")
        wait(10)
        db = false
        end
    end
    if m == 4 then 
        if db then
        db = true
        print("math.random choosed 4.")
        print("obby time!! :DDDD")
        game.Workspace.block1.CanCollide = false
        parts.obby:Clone().Parent = game.Workspace
        wait(60)
        game.Workspace.obby:Destroy()
        script.Parent.ClickDetector.MaxActivationDistance = "32"
        script.Parent.BrickColor = BrickColor.Green()
        game.Workspace.block1.CanCollide = true
        game.Workspace.lobby:Play()
        print("GLOBAL SSEQ START")
        wait(10)
        db = false
        end
    end
    if m == 5 then 
    if db then
        db = true
        print("math.random choosed 5.")
        print("skylark has a present!")
        parts.sky:Clone().Parent = game.Workspace
        wait(15)
        script.Parent.ClickDetector.MaxActivationDistance = "32"
        script.Parent.BrickColor = BrickColor.Green()
        game.Workspace.lobby:Play()
        print("GLOBAL SSEQ START")
        wait(10)
        db = false
        end
    end
   if m == 6 then 
    if db then
        db = true
        print("math.random choosed 6.")
        print("RIP IDK")
        parts.zombieattack:Clone().Parent = game.Workspace
        wait(35)
        game.Workspace.zombieattack:Destroy()
        game.Workspace.Zombie:Destroy()
        script.Parent.ClickDetector.MaxActivationDistance = "32"
        script.Parent.BrickColor = BrickColor.Green()
        game.Workspace.lobby:Play()
        game.Lighting.Brightness = 2
        print("GLOBAL SSEQ START")
        wait(10)
        db = false
        end
     end
     if m == 7 then
    if db then
        db = true
        print("math.random choosed 7.")
        print("noob song!!!111")
        parts.dancing:Clone().Parent = game.Workspace
        wait(38.2)
        game.Workspace.dancing:Destroy()
        game.Workspace.noob:Stop()
        game.Workspace.Disco_Light.Disabled = true
        game.Lighting.Ambient = Color3.new(0,0,0)
        script.Parent.ClickDetector.MaxActivationDistance = "32"
        script.Parent.BrickColor = BrickColor.Green()
        game.Workspace.lobby:Play()
        print("GLOBAL SSEQ START")
        wait(10)
        db = false
        end
     end
     if m == 8 then 
    if db then
        db = true
        print("math.random choosed 8.")
        print("A FLOOD!! GRRGHGRGHG")
        parts.flood:Clone().Parent = game.Workspace
        wait(30)
        game.Workspace.flood:Destroy()
        script.Parent.ClickDetector.MaxActivationDistance = "32"
        script.Parent.BrickColor = BrickColor.Green()
        game.Workspace.lobby:Play()
        print("GLOBAL SSEQ START")
        wait(10)
        db = false
        end
end
if m == 9 then 
    if db then
        db = true
        print("math.random choosed 9.")
        print("jumprope time!!!!")
        game.Workspace.block1.CanCollide = false
        game.Workspace.block2.CanCollide = false
        game.Workspace.block3.CanCollide = false
        game.Workspace.block4.CanCollide = false
        script.Parent.Parent.Part1.CanCollide = false
        script.Parent.Parent.Part2.CanCollide = false
        script.Parent.Parent.Part3.CanCollide = false
        script.Parent.Parent.click.CanCollide = false
        parts.jumper:Clone().Parent = game.Workspace
        wait(40)
        game.Workspace.jumper:Destroy()
        script.Parent.Parent.Part1.CanCollide = true
        script.Parent.Parent.Part2.CanCollide = true
        script.Parent.Parent.Part3.CanCollide = true
        script.Parent.Parent.click.CanCollide = true
        game.Workspace.block1.CanCollide = true
        game.Workspace.block2.CanCollide = true
        game.Workspace.block3.CanCollide = true
        game.Workspace.block4.CanCollide = true
        script.Parent.ClickDetector.MaxActivationDistance = "32"
        script.Parent.BrickColor = BrickColor.Green()
        game.Workspace.lobby:Play()
        print("GLOBAL SSEQ START")
        wait(10)
        db = false
        end
end
if m == 10 then 
    if db then
        db = true
        print("math.random choosed 10.")
        print("O NOES IM FALLIN FOREVER")
        parts.fall:Clone().Parent = game.Workspace
        game.Workspace.Baseplate.CanCollide = false
        game.Workspace.Baseplate.Transparency = 1
        wait(10)
        game.Workspace.fall:Destroy()
        game.Workspace.Baseplate.CanCollide = true
        game.Workspace.Baseplate.Transparency = 0
        script.Parent.ClickDetector.MaxActivationDistance = "32"
        script.Parent.BrickColor = BrickColor.Green()
        game.Workspace.lobby:Play()
        print("GLOBAL SSEQ START")
        wait(10)
        db = false
        end
     end
if m == 11 then 
    if db then
        db = true
        print("math.random choosed 11.")
        print("O NOES IM FALLIN FOREVER")
        parts["Purple Nebula"]:Clone().Parent = game.Lighting
        game.Workspace.worldy:Play()
        game.Workspace.Gravity = 22.2
        game.Workspace.Baseplate.Transparency = 1
        wait(30)
        game.Lighting["Purple Nebula"]:Destroy()
        game.Workspace.worldy:Stop()
        game.Workspace.Baseplate.Transparency = 0
        game.Workspace.Gravity = 196.2
        script.Parent.ClickDetector.MaxActivationDistance = "32"
        script.Parent.BrickColor = BrickColor.Green()
        game.Workspace.lobby:Play()
        print("GLOBAL SSEQ START")
        wait(10)
        db = false
        end
end
end)
0
oh lol why did you do all of that SteamG00B 1633 — 5y
0
not only is that way too much work, but you did it wrong anyway xD SteamG00B 1633 — 5y
0
I fixed it ImSky_RBLX 2 — 5y

Answer this question