Capture point countdown

Im currently trying to make a capture point have a countdown but im unsure how to do so to where if the player leaves the hitbox then the countdown resets ive attempted this:

TimerNum = TimerNum - 1
wait(1)
display.text = TimerNum

but it didnt work out right. (ps im using display as a placeholder for a billboard ui)

heres my full code:

local Hitbox = script.Parent
local TeamN = script.Parent.Values.TeamName

function onTouch(hit)     
    local user = game.Players:GetPlayerFromCharacter(hit.Parent) 
    if user ~= nil then
        script.Parent.TPLoc.BrickColor = user.TeamColor
        TeamN.Value = user.Team.Name
        script.Parent.TPLoc.Position = script.Parent.Values.TPPos.Value
    end 
end 

script.Parent.Touched:connect(onTouch)
1 Like

solved my own problem

local wait1 = 10
local cooldown = false
local timer = script.Parent.Display.Display
local Hitbox = script.Parent
local TeamN = script.Parent.Values.TeamName

function onTouch(hit) 	
	local user = game.Players:GetPlayerFromCharacter(hit.Parent) 
	if user ~= nil then
		if cooldown == false then
			cooldown = true
			for i = wait1,0,-1 do
				timer.Text = i
				wait(1)
			end
		else if cooldown == true then
				wait(wait1)
				cooldown = false
				script.Parent.TPLoc.BrickColor = user.TeamColor
				TeamN.Value = user.Team.Name
				timer.Text = user.Team.Name
				wait(3)
				timer.Text = " "
			end
		end
	end 
end 

script.Parent.Touched:connect(onTouch)