Return pressed function dosent work

I made a code for a command code but even if i press enter / return , it never works , here is the code :

local ti = TweenInfo.new(.6,Enum.EasingStyle.Sine,Enum.EasingDirection.InOut,0,false,0)
local input = ""

print("e")

script.Parent.TextBox.ReturnPressedFromOnScreenKeyboard:Connect(function()
	
	print("e")
	
	input = tostring(script.Parent.TextBox.Text)
	script.Parent.TextBox.Text = ""
	
	game.ReplicatedStorage.Events.System.Execute:FireServer(input)
end)```

Does anyone knows why?
script.Parent.TextBox.FocusLost:Connect(function(enterPressed)
    if enterPressed then
        -- Your Code
    end
end)
3 Likes

Well no because if the player just clicks out of the frame it will execute that

Yeah I edited that it’s actually script.Parent.TextBox, sorry.

1 Like

Why don’t you use User Input service?

no, focus lost can be triggered by just clicking away , so no thats not a possible solution

That’s why it detects if enter is pressed

1 Like

Not optimised , as it checks every time you press a key and im sure there is a better solution

Ok let me try that then because if it actually works like this thats not intuitive at all

Well you can make it so every time you press return it checks if there’s text inside the textbox.

As i said , it is not optimised , and @AWhale_OfATime 's solution turned out to work

:FocusLost() is better it is a built in event for TextBoxes

1 Like