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 4 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:

local timer = 0

script.Parent.enterText.Changed:Connect(function()
    while timer < 60 do
        if timer > 1 then
            print("Timer started")
            wait(1)
            timer = timer + 1
        else
            timer = timer + 1
        end
    end
end)

1 answer

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

You can do this using the Focused event.

-- Simplified version
local timer = 0

script.Parent.enterText.Focused:Connect(function()
    for i = 0, 60 do
        timer = i + 1
        wait(1)
    end
end)
0
Works, thanks. RyanTheLion911 195 — 4y
Ad

Answer this question