Want to wait for the barrier to close to reactivate this ticket scan script

Hello.

I have this script, it’s working.

script.Parent.Touched:connect(function(p)
	if p.Parent.Name == "Ticket" then
		script.Parent.Beep:Play()
		script.Parent.Parent.DL.Motor.DesiredAngle = 1.6
		script.Parent.Parent.DR.Motor.DesiredAngle = 1.6
		script.Parent.Parent.DL.Motor.MaxVelocity = 0.035
		script.Parent.Parent.DR.Motor.MaxVelocity = 0.035
		wait(2)
		script.Parent.Parent.DL.Motor.DesiredAngle = 0
		script.Parent.Parent.DR.Motor.DesiredAngle = 0
	end
end)

So, I would like to make it when I touch it the barrier opens then wait until close. The beep sound keep beeping when touching on scanner so it should only beep 1 time.

Simply add an :Pause() function.

if the sound just keeps going then you need a pause or stop but
if the problem is that its playing multiple times when touched then you need a debounce
i think

Add a debounce variable. To do this, before the function you’re going to want to add

local debounce = false

then, for the if statement, add a check to see if the debounce is false, and if so, change it to true and then carry out the function. It should look like this:

if p.Parent.Name == "Ticket" and debounce == false then
debounce = true

finally, at the end of the if statement, set debounce back to false. The final script should look like this:

local debounce = false
script.Parent.Touched:connect(function(p)
	if p.Parent.Name == "Ticket" and debounce == false then
        debounce = true
		script.Parent.Beep:Play()
		script.Parent.Parent.DL.Motor.DesiredAngle = 1.6
		script.Parent.Parent.DR.Motor.DesiredAngle = 1.6
		script.Parent.Parent.DL.Motor.MaxVelocity = 0.035
		script.Parent.Parent.DR.Motor.MaxVelocity = 0.035
		wait(2)
		script.Parent.Parent.DL.Motor.DesiredAngle = 0
		script.Parent.Parent.DR.Motor.DesiredAngle = 0
        debounce = false
	end
end)

Edit: this post got no love ;(

1 Like

local debounce = false
‘’’
script.Parent.Touched:connect(function(p)
if p.Parent.Name == “Ticket” and debounce == false then
debounce = true
script.Parent.Beep:Play()
script.Parent.Parent.DL.Motor.DesiredAngle = 1.6
script.Parent.Parent.DR.Motor.DesiredAngle = 1.6
script.Parent.Parent.DL.Motor.MaxVelocity = 0.035
script.Parent.Parent.DR.Motor.MaxVelocity = 0.035
wait(2)
script.Parent.Parent.DL.Motor.DesiredAngle = 0
script.Parent.Parent.DR.Motor.DesiredAngle = 0
Wait(DESIREDTIME)
debounce = false
end
end)
‘’’

Sorry this was wrote on mobile lol

1 Like

It’s okay lol and thanks for helping.

1 Like