Hi there! I have a wonderful door I love so dear, but I cannot figure out to put a cooldown on its usage. It is a door that allows a tool (a card) to grant access to the door (tool turns the door to non-collidable).
Here's the problem - when a card hits the sensor of the door to allow access, if you move your character back and forth, it plays the "opening" and other noises a million times. It needs a cooldown of some sort so the it only registers the card once, say, every 10 seconds. My friend and I believe it should need just a simple "wait" command, we have been messing with it but can't quite figure this one out! Messing with the current wait commands just delays the door with doing what it needs to do, not putting a cooldown on the card registering to the door. I would very much appreciate the help!
print("Advanced SpecialDoor Script loaded")
permission = { "Fire Dorm" }
Door = script.Parent.Parent.PersonDoor
Door2 = script.Parent.Parent.PersonDoor2
DoorMesh = script.Parent.Parent.PersonDoor.Mesh
Sensor = script.Parent
Sounds = script.Parent.Parent.Sounds
function checkOkToLetIn(name)
for i = 1,#permission do
if (string.upper(name) == string.upper(permission[i])) then return true end
end
return false
end
function onTouched(hit)
print("Sensor Hit")
local human = hit.Parent:findFirstChild("Humanoid")
if (human ~= nil ) then
--
print("Human touched door")
if (checkOkToLetIn(human.Parent.Name)) then
print("Human passed test")
Wait(0.001)
script.Parent.Parent.Dot1.Transparency = 0
Sounds.Beep:Play()
wait(0.4)
script.Parent.Parent.Dot2.Transparency = 0
Sounds.Beep2:Play()
wait(0.4)
script.Parent.Parent.Dot3.Transparency = 0
Sounds.Beep2:Play()
wait(0.4)
script.Parent.Parent.Open.Transparency = 0
script.Parent.Parent.Close.Transparency = 1
Sounds.Beep2:Play()
wait(0.2)
Sounds.OpenSound1:Play()
wait(0.1)
script.Parent.Parent.HandlePart3.Transparency = 0
script.Parent.Parent.HandlePart4.Transparency = 0
script.Parent.Parent.HandlePart.Transparency = 1
script.Parent.Parent.HandlePart2.Transparency = 1
script.Parent.Parent.Handle2.Transparency = 1
script.Parent.Parent.Handle5.Transparency = 0
script.Parent.Parent.Acess.Mesh.Scale = Vector3.new(0.9, 0.5, 1.01)
Door.Transparency = 1
Door2.Transparency = 0
Door2.Wedge.Transparency = 0
Door2.Wedge2.Transparency = 0
Door.Wedge.Transparency = 1
Door.Wedge2.Transparency = 1
wait(0.02)
Door.CanCollide = false
script.Parent.Parent.Dot1.Transparency = 1
script.Parent.Parent.Dot2.Transparency = 1
script.Parent.Parent.Dot3.Transparency = 1
wait(3)
script.Parent.Parent.Open.Transparency = 1
script.Parent.Parent.Close.Transparency = 0
script.Parent.Parent.HandlePart3.Transparency = 1
script.Parent.Parent.HandlePart4.Transparency = 1
script.Parent.Parent.HandlePart.Transparency = 0
script.Parent.Parent.HandlePart2.Transparency = 0
script.Parent.Parent.Handle2.Transparency = 0
script.Parent.Parent.Handle5.Transparency = 1
Sounds.OpenSound2:Play()
script.Parent.Parent.Acess.Mesh.Scale = Vector3.new(0.01, 0.01, 0.01)
Door.CanCollide = true
Door.Transparency = 0
Door2.Transparency = 1
Door2.Wedge.Transparency = 1
Door2.Wedge2.Transparency = 1
Door.Wedge.Transparency = 0
Door.Wedge2.Transparency = 0
end
end
end
connection = Sensor.Touched:connect(onTouched)
Thanks!

1 comment
Thank you so much for your answer and explaining the debounce to me! The debounce is something else my friend tried but unfortunately your script breaks the door :( . Not entirely, though - it only sometimes decides to work. It is quite strange! Thank you for trying to help.