Debounce
I understand why you have tried to be using the wait(10)
for the script, but a debounce system is quite effective in my opinion. Basically, you set a variable in your script for example, named 'debounce'. Then before you do anything in the function, you check if debounce is false, and if it is, then set it to true and continue. At the end, you need to then add the wait(10)
and then set the variable to false.
Example
01 | local buttonPressed = false |
04 | Workspace.Button.Touched:connect( function (hit) |
05 | if not buttonPressed then |
11 | print ( "Button pressed" ) |
Taken from the wiki
Fixed script
Here is your fixed script!
01 | print ( "Advanced SpecialDoor Script loaded" ) |
05 | permission = { "Fire Dorm" } |
06 | Door = script.Parent.Parent.PersonDoor |
07 | Door 2 = script.Parent.Parent.PersonDoor 2 |
08 | DoorMesh = script.Parent.Parent.PersonDoor.Mesh |
10 | Sounds = script.Parent.Parent.Sounds |
13 | function checkOkToLetIn(name) |
14 | for i = 1 ,#permission do |
16 | if (string.upper(name) = = string.upper(permission [ i ] )) then return true end |
21 | function onTouched(hit) |
22 | if debounce = = false then |
25 | local human = hit.Parent:findFirstChild( "Humanoid" ) |
26 | if (human ~ = nil ) then |
28 | print ( "Human touched door" ) |
30 | if (checkOkToLetIn(human.Parent.Name)) then |
31 | print ( "Human passed test" ) |
33 | script.Parent.Parent.Dot 1. Transparency = 0 |
36 | script.Parent.Parent.Dot 2. Transparency = 0 |
39 | script.Parent.Parent.Dot 3. Transparency = 0 |
42 | script.Parent.Parent.Open.Transparency = 0 |
43 | script.Parent.Parent.Close.Transparency = 1 |
46 | Sounds.OpenSound 1 :Play() |
48 | script.Parent.Parent.HandlePart 3. Transparency = 0 |
49 | script.Parent.Parent.HandlePart 4. Transparency = 0 |
50 | script.Parent.Parent.HandlePart.Transparency = 1 |
51 | script.Parent.Parent.HandlePart 2. Transparency = 1 |
52 | script.Parent.Parent.Handle 2. Transparency = 1 |
53 | script.Parent.Parent.Handle 5. Transparency = 0 |
54 | script.Parent.Parent.Acess.Mesh.Scale = Vector 3. new( 0.9 , 0.5 , 1.01 ) |
56 | Door 2. Transparency = 0 |
57 | Door 2. Wedge.Transparency = 0 |
58 | Door 2. Wedge 2. Transparency = 0 |
59 | Door.Wedge.Transparency = 1 |
60 | Door.Wedge 2. Transparency = 1 |
62 | Door.CanCollide = false |
63 | script.Parent.Parent.Dot 1. Transparency = 1 |
64 | script.Parent.Parent.Dot 2. Transparency = 1 |
65 | script.Parent.Parent.Dot 3. Transparency = 1 |
68 | script.Parent.Parent.Open.Transparency = 1 |
69 | script.Parent.Parent.Close.Transparency = 0 |
70 | script.Parent.Parent.HandlePart 3. Transparency = 1 |
71 | script.Parent.Parent.HandlePart 4. Transparency = 1 |
72 | script.Parent.Parent.HandlePart.Transparency = 0 |
73 | script.Parent.Parent.HandlePart 2. Transparency = 0 |
74 | script.Parent.Parent.Handle 2. Transparency = 0 |
75 | script.Parent.Parent.Handle 5. Transparency = 1 |
76 | Sounds.OpenSound 2 :Play() |
77 | script.Parent.Parent.Acess.Mesh.Scale = Vector 3. new( 0.01 , 0.01 , 0.01 ) |
78 | Door.CanCollide = true |
80 | Door 2. Transparency = 1 |
81 | Door 2. Wedge.Transparency = 1 |
82 | Door 2. Wedge 2. Transparency = 1 |
83 | Door.Wedge.Transparency = 0 |
84 | Door.Wedge 2. Transparency = 0 |
93 | connection = Sensor.Touched:connect(onTouched) |
Thanks for reading
Thanks for reading my answer! If it help you, make sure to upvote it or set it as the correct answer! Thanks! Hope it helped.