Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

I want a timer to start when a TextBox has changed, but won't work. Why?

Asked by 5 years ago

I have a TextBox and I want it to time the amount of time it takes to type in a certain piece of text, however, whenever I have used the 'Changed' function it just starts multiple timers every time the TextBox has changed. This is what I have come up with so far but can't figure out the rest. (Local script)

Code:

01local timer = 0
02 
03script.Parent.enterText.Changed:Connect(function()
04    while timer < 60 do
05        if timer > 1 then
06            print("Timer started")
07            wait(1)
08            timer = timer + 1
09        else
10            timer = timer + 1
11        end
12    end
13end)

1 answer

Log in to vote
1
Answered by
bluzorro 417 Moderation Voter
5 years ago

You can do this using the Focused event.

1-- Simplified version
2local timer = 0
3 
4script.Parent.enterText.Focused:Connect(function()
5    for i = 0, 60 do
6        timer = i + 1
7        wait(1)
8    end
9end)
0
Works, thanks. RyanTheLion911 195 — 5y
Ad

Answer this question