How to detect when a player stops typing in textbox surface gui?

I have a surfacegui text box and put this script inside it. It’s supposed to reset the text when the player clicks out of the text box but it doesn’t trigger the event and I don’t know why.

local textBox = script.Parent
local defaulttext = textBox.Text

--when a player stops typing reset text
textBox.FocusLost:Connect(function()
		textBox.Text = defaulttext
end)
1 Like

local variables are not static, what you’re basically doing is setting the text box’s text to itself which does nothing.

if your definition of “reset” is clearing the text in the textbox, just get rid of the variable and do:

textBox.FocusLost:Connect(function()
		textBox.Text = ""
end)

i hope what i said made sense i suck at explaining stuff

my script works for my textbox in player gui. i dont want to clear the textbox just put the original text back. my problem is the event doesnt even fire, i checked with a print statement

That is not even a event,the event has not even been fired in the first place

like i said it works in my local script. is there an equivalent for server scripts or surfacegui textboxes?

Yeah, no. Completely incorrect. TextBox.FocusLost is a valid event.

FocusLost only fires in LocalScripts (see TextBox | Documentation - Roblox Creator Hub)

as for an equivalent, you could always use a RemoteEvent i guess

Who will even use focus lost as an event,I think remote event might be better than this

So you’re saying even though this is a surfacegui in a part on the server, i need to also use a local script in addition to the server script? how is that possible for this?

Focuslost is an event that fires when the client’s focus leaves a textbox. It helps detect when a client clicks/taps outside of the TextBox. Keyword client meaning it cannot be used for this. I’m simply asking for an equivalent for the server since nothing seems to work. How do you suggest I use a remote event with this server-sided object, let alone without focuslost in the local script, since you seem to adamant against the use of it.

Did you want it to replicate to other players? If not, just use a regular Script (exact same code) with RunContext as Client:

image

image

Video of it functioning (hopefully the video works):

This is located in Workspace.

The only way to replicate it to other players would likely be through the use of RemoteEvents.

thanks man, i just needed some way to detect it

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.