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

How do you hook up a trigger to the Enter key while allowing players to type in a textbox?

Asked by
Dr_Doge 100
8 years ago

Sorry I cant show you the actual script because I dont want it to be leaked, but heres what I got:

I have a function hooked up to make it so that when you press the Enter key, It prints whats inside a Textbox.

The only problem is, you have to click enter twice when typing in the Textbox. Once to Exit out of the Textbox, and once to print. How do I make it so that you only need to press Enter once?

I guess I can put this small part of the script down:

Num=1
Mouse.KeyDown:connect(function(Key) -- When the player presses a key
    if Key == string.char(13) then -- If the player Pressed the enterkey
    AddText(Num.."> "..Textbox.Text) -- Thats a custom function that works. It prints to a custom Console.
    Textbox:CaptureFocus()
    Num=Num+1
end
end)

1 answer

Log in to vote
1
Answered by
XAXA 1569 Moderation Voter
8 years ago

You may want to listen to the FocusLost event of the textbox. This fires every time focus on the textbox is lost, either via clicking out of the textbox or pressing enter.

Num=1
Textbox.FocusLost:connect(function(enterPressed)
    -- check if pressing enter caused the textbox to lose focus
    if enterPressed then
        AddText(Num.."> "..Textbox.Text)
        Textbox:CaptureFocus() -- ??
        Num=Num+1
    end
end)
0
o CaptureFocus will Capture the focus of the Textbox. Its a Roblox function. Dr_Doge 100 — 8y
0
edited, the first param of the FocusLost function is a bool that says whether or not enter was pressed to release the TextBox. The second argument is the InputObject that caused the TextBox to lose focus. @your latest comment: I know. I just don't know why you're doing it. XAXA 1569 — 8y
0
Yeah the thing returns true, u dont need to do anything else. Thanks for the Help! Dr_Doge 100 — 8y
Ad

Answer this question