Why is my debounce not working?

I’m pretty new to scripting and I can’t seem to figure what is going on with this part of my code. Basically, when the President enters a safe room in less than 10 seconds, the round ends and the President/Bodyguards win. I should note that when the president enters the safe room, the floor has a ‘Touched’ event (I don’t know how to detect if a player is inside of a brick so I used a floor(or if you can even do that)). However when the president enters the safe rom and touches the floor, the message I used to test if the code gets spammed, gets spammed and repeats everything in the function multiple times causing some serious lag. I’m confused because I triple checked to make sure the debounce is correct and I can’t find anything wrong with it. I have a screenshot of the console in-game:
https://gyazo.com/6bab7a8cc478423134caa0ef80e07324

Here is the function used to end the round:
https://gyazo.com/fb952f8e100a335d0bbef419684196b1

Here is the code for when the floor gets touched by the President:
https://gyazo.com/ce61177a919fed9723b55255957230dd

I think it may have to deal with the code used to end the round if the President doesn’t make it to one of the safe rooms, along with other variables which should be pretty self-explanatory, not sure though:
https://gyazo.com/7250b2dc0495fcaa9d36eb8d2c1146d9

I’ve looked all over the internet and it has been driving me crazy, I might be missing something or I could be doing something completely wrong. Once again I am pretty new to scripting, so please go easy on me heheh. :slightly_smiling_face:

EDIT
Problem resolved, thank you to everyone who contributed in helping me and giving some great tips!

The if statement that includes the debounce doesn’t close. Once you fix that, it should work.

instead of doing “if not deb then” on line 181, you do “if deb == false then”. Here’s a tip: next time you encounter a problem you should use print commands to locate the problem, that’s how many devs do it, in this case, you would do “print(deb)” on line 183, and if the output was false, then you would know that there is a problem around there.

2 Likes

if not deb is equal to if deb == false, as with other booleans. Of course it can be confused with the boolean being nil, but it shouldn’t be a worry in this instance.

1 Like

How would I check if the if statement on line 180 is not closed? Because I think it is closed

If there isn’t an end after the code under the if statement, it isn’t closed. Right now the script thinks that there is also an elseif statement, which is confusing the script.

Also, I suggest indenting your code correctly so you don’t get as easily confused. It’s a good habit to have when coding!

the amount of “if” and “function” statements is the number of ends, desired was right, indenting is a good habit — you can tell how much ends there are by the number of indents.

1 Like

Everytime the president touches the button you set “deb” to false.
Essentially you have written this:

--...
local deb = false
--...
if not deb

So just put line #174 above line #172 and it should work.

2 Likes

Wow! I knew it was something simple lol, it worked just fine.

Thank you :smiley: