Yield For Player Input

Given a TextBox (Focusable, Type-able), is there a way to accomplish the pseudocode method below to yield the current thread until the player has entered input into the TextBox and hit enter?

TextBox.Focused:Once(function()
    local textThePlayerTyped = yieldForInput()
    TextBox:Destroy() -- If it doesn't yield, TextBox will be destroyed mid-type
    print(textThePlayerTyped)
end)

You can try this

TextBox.Focused:Once(function()
    TextBox.FocusLost:Wait() --yields until FocusLost fires
    local textThePlayerTyped = TextBox.Text
    TextBox:Destroy()
    print(textThePlayerTyped)
end)

Though if a player clicks off it might not have the behavior you want.

If you need better, generally you can do without it by designing the next part to live in a function you call from a custom event, but if you really need it to yield you can set up your own event thing for it by using an extra object or a property and waiting for a change in state from it that you cause in your detection.

1 Like