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

How would I script for a click detector to destroy after it's clicked once and then come back?

Asked by 6 years ago

How would I script for a click detector to destroy after it's clicked once and then after you wait two mins, the clickdetector comes back?

I think the code would have:

Script.Parent:Destroy()

and maybe wait(120)

and then script.Parent:Clone()

but i am a bit confused.

Also, I think you would have to put the script in the Clickdetector.

Thank You and help is appreciated

0
I think you want like a 2 minute debounce? Like a cool down. So, just a cool down after it's clicked is simple enough. You don't need to physically destroy it. KingLoneCat 2642 — 6y
0
script.Parent:Destory() destroys the whole script. clrik 8 — 6y
0
oh ok aspiringstar346 8 — 6y

3 answers

Log in to vote
0
Answered by 6 years ago
local click = script.Parent.ClickDetector --or wherever it is

click.MouseClick:Connect(function(player)
     click.Parent = nil
     wait(20)
     click.Parent = script.Parent
end)
Ad
Log in to vote
0
Answered by 6 years ago

Hi aspiringstar346,

You just need a cool down for the function, you don't need to physically destroy the click detector. Here, this is how I would do the function with the cool down.

local detector = script.Parent; -- The Click Detector, which is the script's parent.
local deb = false; -- The debounce for the click detector. This is the boolean value we're going to change to activate cool down.

detector.MouseClick:Connect(function(plr) -- Anonymous function for the Mouse Click on the Click Detector.
    if not deb then -- Checks if deb is false, and if it is, then it can go ahead and run the function.
        deb = true; -- Makes it true so that this function can't be run until deb is false.
        print("It was clicked.");   -- Prints "It was clicked" for testing purposes.
        wait(120);   -- Waits for 120 seconds since that's the cool down.
        deb = false; -- Makes deb false so that the function can run again.
    end    -- end for if statement
end)     -- end for anonymous function.

Think of debounce as a door. You close the door when you set deb to true, and you open it once you set it back to false. And the if not deb then is what is checking if the door is open.

Here is where you can find more about debounce and how to use it properly.

Well, I hope I helped and have a wonderful day/night.

Thanks,

Best regards,

~~ KingLoneCat

0
sorry but I really don't understand about debounce and I think I need to learn more about the basics of scripting before I learn about debounce. Thank You fro Helping Me aspiringstar346 8 — 6y
0
No problem, and I am sorry I couldn't help much. KingLoneCat 2642 — 6y
Log in to vote
0
Answered by 6 years ago
1
local click = script.Parent.ClickDetector
2

3
click.MouseClick:Connect(function(player)
4
     click.Parent = game.Players
5
     wait(20)
6
    game.Players:FindFirstChild("click").Parent = thing you got the click detector in
7
end)

Answer this question