Help with stopping the timer

Hello,

So I’m makinig a Christmas Quiz. And I came far but I made a timer for the questions so you have to choose an answer within the time. But I can’t stop the timer if the answer is correct.

And I do want to have that. So if anyone knows how to do that that would be helpful!!

Here’s the script in case you need it;

local stop_Watch = script.Parent
local char_when = script.Parent.Parent.Value



if char_when.Value == true then
	
	local time_Finished = 0.0
	
	stop_Watch.Text = "20.0"
	local txtValue = 20.0
	
	local value = 20.0
	
	wait(0.5)
	
	while true do
		
		wait(.1)
		value -= 0.1
		
		stop_Watch.Text = value
		if value <= 1 then
			stop_Watch.Text = 0
		end
		
		local correct = script.Parent.Parent.Parent.Correct
		
		txtValue -= 0.1
		
		local time_Up = script.Parent.Parent.Parent.TimesUP
		
		if txtValue <= 1 then
		
			
			if txtValue <= 1 then
				time_Up.Visible = true

				local question = script.Parent.Parent.Question
				question:Destroy()

				local answer_Box = script.Parent.Parent
				answer_Box:Destroy()

				stop_Watch.Text = "0"
				break
			end
		end
	end
end

You could just check if an answer has been inputted and if it is correct upon each cycle of the loop, if the answer is correct record the time and break out of the loop with a break statement.

Your code is messy, hope this helps you.

local stop_Watch = script.Parent
local char_when = script.Parent.Parent
Time = 20

local function Countdown(Time)
    if char_when.Value == true then
        repeat wait(0.1)
            Time -= 0.1
            stop_Watch.Text = Time
        until Time == 0
    end
end)

char_when:GetPropertyChangedSignal("Value"):Connect(Countdown)

if stop_Watch.Text == '0' then
    script.Parent.Parent.Parent.TimesUP.Visible = true
    script.Parent.Parent:Destroy()
end

@Forummer How do I record the last updated second when the player checks if the answer is correct?