#textbox focus events not working

1 messages · Page 1 of 1 (latest)

woven monolith
#

Im trying to make a translator. i tried both serverscript andlocalscript and print debug but it wont trigger

#

Script for reference:

local leftlang = script.Parent.LeftLang.SurfaceGui.TextLabel.Text
local rightlang = script.Parent.RightLang.SurfaceGui.TextLabel.Text
local switch = script.Parent.Switch.SurfaceGui.ImageButton
local input = script.Parent.Input.SurfaceGui.TextBox
local output = script.Parent.Output.SurfaceGui.TextLabel

local inputeng = true

function Output()
    print("what")
    if inputeng then
        if input.Text == {"Hello" or "Hi" or "hello" or "hi"} then
            output.Text = "Hül"
        else
            output.Text = input.Text
        end
    end
end

input.InputEnded:Connect(function()
    print(1)
    Output()
end)```
sour leaf
#

lemme help

#

Could you show me your exporer and where it is placed

woven monolith
#

mind you all events work properly except for input and focus events

atomic turret
atomic turret
#

Localisation refers to translating

#

You’re making a translator 🤷‍♂️

#

See the overlapping properties?

woven monolith
#

localiwhat

#

the problem rn is about the textbox

#

not the localisation thingie

woven monolith
#

updated script

local leftlang = script.Parent.LeftLang.SurfaceGui.TextLabel.Text
local rightlang = script.Parent.RightLang.SurfaceGui.TextLabel.Text
local switch = script.Parent.Switch.SurfaceGui.ImageButton
local input = script.Parent.Input.SurfaceGui.TextBox
local output = script.Parent.Output.SurfaceGui.TextLabel

local inputeng = true

function Output(enterpressed, inpobj)
    print(1)
    input = script.Parent.Input.SurfaceGui.TextBox
    output = script.Parent.Output.SurfaceGui.TextLabel
    if enterpressed then
        if inputeng then
            if input.Text == "Hello" then
                output.Text = "Hül"
            else
                output.Text = input.Text
            end
        end
    end
end

input.FocusLost:Connect(Output)```
timber roost
#

Got it! You're working on a Roblox translator and trying to trigger an event when a TextBox loses focus (like when input ends). Your event isn't firing, and you want to fix that.

Here are a few notes and fixes:

  1. Event choice: Use FocusLost instead of InputEnded

    InputEnded fires when any input ends (e.g., key or mouse input) — not specifically when the textbox loses focus.

    To detect when the user finishes typing in a TextBox (loses focus), use FocusLost.

input.FocusLost:Connect(function(enterPressed)
print("Focus lost, enter pressed:", enterPressed)
Output()
end)

enterPressed is true if the player pressed Enter to end editing, false if they clicked elsewhere.
2. Fix your condition for checking input.Text

This condition is incorrect:

if input.Text == {"Hello" or "Hi" or "hello" or "hi"} then

You cannot compare a string to a table like that.

Instead, you can do:

local text = input.Text:lower()
if text == "hello" or text == "hi" then
output.Text = "Hül"
else
output.Text = input.Text
end

  1. Serverscript vs Localscript

    GUI and input events like FocusLost only work in LocalScripts.

    If you run this in a ServerScript, it won’t detect player GUI input events.

Make sure your script is a LocalScript inside the GUI hierarchy.
4. Full fixed version

local leftlang = script.Parent.LeftLang.SurfaceGui.TextLabel.Text
local rightlang = script.Parent.RightLang.SurfaceGui.TextLabel.Text
local switch = script.Parent.Switch.SurfaceGui.ImageButton
local input = script.Parent.Input.SurfaceGui.TextBox
local output = script.Parent.Output.SurfaceGui.TextLabel

local inputeng = true

function Output()
print("Output function called")
if inputeng then
local text = input.Text:lower()
if text == "hello" or text == "hi" then
output.Text = "Hül"
else
output.Text = input.Text
end
end
end

input.FocusLost:Connect(function(enterPressed)
print("Focus lost, enterPressed:", enterPressed)
Output()
end)

Quick checklist for troubleshooting:

Use LocalScript, not ServerScript.

Place the LocalScript somewhere under StarterGui or inside the GUI.

Use FocusLost event, not InputEnded.

Fix your conditional logic for string matching.

If you want, I can help you extend the translator logic or help test it! Just let me know.

#

This isnt Ai i used brain

woven monolith
#

are you sure

#

😭

timber roost
#

Yeah, duh...

#

I typed it fkn out]

woven monolith
#

i mean

#

it says it needs to be a local script

#

but

#

its on a surface gui