001 | function BP() |
002 | script.Parent.CFrame = script.Parent.CFrame * CFrame.new(-. 06 , 0 , 0 ) |
003 | script.Parent.ClickSound:Play() |
004 | script.Parent.ClickDetector.MaxActivationDistance = 0 |
005 | end |
006 | function BU() |
007 | script.Parent.CFrame = script.Parent.CFrame * CFrame.new(. 06 , 0 , 0 ) |
008 | script.Parent.ClickDetector.MaxActivationDistance = 10 |
009 | end |
010 | function onClicked() |
011 | local a = math.random( 1 , 24 ) |
012 | if a = = 1 then |
013 | BP() |
014 | game.ReplicatedStorage.Coins:Clone().Parent = game.Workspace |
015 | script.Parent.Sounds.Coinsound:Play() |
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. Howver 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.
Making a debounce is actually quite simple! At the beginning of your script, simply make a variable that will represent your debounce. This can literally be named anything, as long as it dosnt end up interfering with another variable. I very much encourage you to give it its own unique name. Set it to true or false, it really dosnt matter either way, but we will have to remember what it is set to later on.
Lets say I named my debounce "Debounce" and I set it to true. (local Debounce = true)
Now for the next part, we will add an if statement after the function is triggered. It seems your looking to implement the debounce into the function on line 10. ("function onClicked()")
Immediately after line 10, we would add an if statement checking if the debounce is true or false
Example:
1 | function onClicked() |
2 | if Debounce = = true then |
3 | Debounce = false |
4 | --stuff that happens here-- |
5 | --Lets add a cooldown here, so debounce will not become true again until the wait is over-- |
6 | wait( 30 ) |
7 | Debounce = true |
8 | end |
9 | end ) |
This will make it so the function will not run again until debounce is true again, since debounce will not become true until the wait() ends, the button will not work again until the amount of time I put in the wait. Let me know if you have any more questions!
Don’t worry mate I’ve gotcha back... hopefully.
For the BP
1 | Debounce = 0 |
2 | function BP() |
3 | If Debounce = = 0 then |
4 | script.Parent.CFrame = script.Parent.CFrame * CFrame.new(-. 06 , 0 , 0 ) |
5 | script.Parent.ClickSound:Play() |
6 | script.Parent.ClickDetector.MaxActivationDistance = 0 |
7 | Debounce = 1 |
8 | end |
9 | end |
Then for your BU
1 | function BU() |
2 | script.Parent.CFrame = script.Parent.CFrame * CFrame.new(. 06 , 0 , 0 ) |
3 | script.Parent.ClickDetector.MaxActivationDistance = 10 |
4 | - Then put your wait time here with wait() |
5 | Debounce = 0 |
6 | end |
That should be everything, I’m really tired so expect something from me to be 50/50
I still didn't get the help I needed, the reason I put the disabling clicking effect into these functions is so that it disables it for a certain amount of time for each outcome. Having one set wait time will not work. Remember, I want to replace just setting the MaxClickDistance to 0 with debounce