Event Touched with For Loops

This will call a function that will run as a timer for you, if you want the timer to not take up time before moving on to the next part of the function when part is touched simply use a coroutine.wrap(function()).

local timerEnd = 20 -- this will make it last for 20 seconds (can change num to whatever you want)
local timePassed = 0 -- put it here so you can access it anywhere
local function timer()
  timePassed = 0
  while true do
    task.wait(1)
    timePassed += 1
    if timePassed >= timerEnd  then
      break --stops loop
    end
  end
end

Part1.Touched:Connect(function()
  timer()
  --below put whatever event you want to play after timer is done
end)

Can also use the tick function Tick() if you want to have it constantly there for you to check rather than checking every increment.

1 Like