Problem with a Timer

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? What I’m trying to achieve is a timer that will run when a part is touched and then the timer gets to zero, the timer Gui disappears.

  2. What is the issue? Include screenshots / videos if possible! So the timer works. When you touch the part, the timer will appear. But if you keep touching that part, the timer speeds up, and if you step of the part, the timer stops.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub? I just tried to figure it out.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

local seconds = script.Parent.Parent.Time
local debounce = false

script.Parent.Text = seconds.Value

function onTouched(hit)
  wait(1)
  script.Parent.Visible = true
  seconds.Value = seconds.Value -1
  local debounce = true
  script.Parent.Text = seconds.Value
  if seconds.Value == 0 then
script.Parent.Visible = false
local debounce = false
end
   end
game.Workspace.Collosuem.Touched:connect(onTouched)

Have a great day! :slight_smile:

You have to add a wait(1) in your debounce and you need a conditional to check the debounce as well.

if not debounce then --false
    
    debounce = true
    --do things
    wait(1)
    debounce = false

end
1 Like

@TheCarbyneUniverse

'''
   local seconds = script.Parent.Parent.Time

local debounce = false

script.Parent.Text = seconds.Value

function onTouched(hit)
if not debounce then

debounce = true
script.Parent.Visible = true
seconds.Value = seconds.Value -1
script.Parent.Text = seconds.Value
wait(1)
debounce = false
end
end

game.Workspace.Collosuem.Touched:connect(onTouched)

'''

Is this better?
(Sorry for not indenting)