When I asked my first question, it was answered but somebody else also suggested adding a debounce script to my restricted door. Could I get help with that? http://wiki.roblox.com/index.php?title=Debounce
01 | local door = script.Parent |
02 |
03 | function open() |
04 | -- This function will open the door. |
05 | door.CanCollide = false -- Make players able to walk through the door. |
06 |
07 | for transparency = 0 , 1 , . 1 do |
08 | door.Transparency = transparency |
09 | wait(. 1 ) |
10 | end |
11 | end |
12 |
13 | function close() |
14 | -- This function will close the door. |
15 | for transparency = 1 , 0 , -. 1 do |
Just add in a variable named something like local debounce = false
and then set it to true when they touch it. Have it wait a second and then set it to false. Before you go and set it to true, though, have it check to see if it's false.
To add a debounce, you can use a bool value to indicate whether the debounce is on or off. When it is on, simply don't open the door even if an allowed player touches it.
For example:
01 | local debounce = false |
02 |
03 | part.Touched:connect( function (touch) |
04 | if not debounce then |
05 | debounce = true |
06 |
07 | touch:Destroy() |
08 | end |
09 |
10 | wait( 1 ) |
11 | debounce = false |
12 | end ) |
The above example makes sure the script can only be run once a second at maximum.
Adding a debounce i simple, Example;
1 | local debounce = true |
2 |
3 | script.Parent.Touched:Connect( function () -- change this if you want |
4 | if debounce = = true then -- checks if the debounce is true |
5 | debounce = false --changes it to false |
6 | -- put your script in here |
7 | debounce = true --sets it to true after the script has run |
8 | end |
You can find more here: https://wiki.roblox.com/?title=Debounce
A debounce can actually be anything. It does not have to be a boolean. It can be a number or a string too.
HOW TO USE DEBOUNCE
You use debounce by first defining the variable outside of the given function:
1 | DebounceNumber = 1 -- Notice what I'm doing here |
Then start your function, and when you start your function, add this:
1 | function ILoveRoblox() |
2 | if DebounceNumber = = 1 then |
3 | DebounceNumber = 2 -- Again, doesn't have to be a number, it can be a boolean or string. |
Followed by the rest of the script:
1 | print ( "I love Roblox" ) |
2 | wait( 3 ) |
3 | DebounceNumber = 1 |
4 | end |
5 | if not DebounceNumber = = 1 then break -- Debounce line |
6 | end |
7 | script.Parent.Touched:Connect(ILoveRoblox) |
As I said before, a debounce can be anything (boolean, string, number). A debounce takes action when the value of the debounce variable is changed, and an if statement declares that "Hey, if this variable is equal to this value, start the function. If it is not equal to this value, stop the function immediately." That is the true way to use a debounce variable.