How do i make a textbox's text change another button's text?

so here i have a simple setup where theres a textbox and a textbutton. my idea is for the player to input text through the box and for it to be displayed on the textbutton.


(textbutton above, textbox below)

the issue here is that it seems like the textbox only changes client-side, and i want the changes to also be detected server-side, in order to be readable by another script to set the textbutton’s text (also to be seen by other players)

i have tried asking multiple AIs, including roblox’s assistant, but to no avail. can anyone tell me how to actually do it? help will be much appreciated.
i’m relatively new to GUIs and i really need some help. thanks in advance

1 Like

if you want the text of a textbox to be shared for everyone you would do that using a remote event.
when a player inputs text you send it to the server the server filters it and sends it back to every client. Then every client displays the text they received from the server

-- LocalScript
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local changeTextRE = ReplicatedStorage:WaitForChild("ChangeText")

local textBox = script.Parent.TextBox

textBox.FocusLost:Connect(function()
	changeTextRE:FireServer(textBox.Text)
end)

changeTextRE.OnClientEvent:Connect(function(text)
	textBox.Text = text
end)
-- ServerScript
local Players = game:GetService("Players")

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local changeTextRE = ReplicatedStorage.ChangeText

local currentText = "Text"

changeTextRE.OnServerEvent:Connect(function(player, text)
	
	local filteredText = text --> make sure to filter it before sending it!
	currentText = filteredText
	
	changeTextRE:FireAllClients(currentText)
end)

-- Make sure players who join later also have the most up to date text
Players.PlayerAdded:Connect(function(player)
	changeTextRE:FireClient(player, currentText)
end)

Don’t forget to filter the text first using TextService before sending it to other client.
And here is more info about Text Filtering.
Hope this helps.

alright, i’ll be testing this real quick

it didn’t work, the text inputted by the player didn’t appear on the server side

image
(client side)
image
(server side)

it also didn’t throw any errors, so i dont know what really happened

This is normal because we never change the property of the text on the server.
I did it that way because gui should always be edited on the clients locally. currently the server keeps track of what the text is using the currentText variable.

And now that i think about it this is not needed you could instead edit the text in StarterGui so it will update automatically.

changing the server script to this will fix it

local Players = game:GetService("Players")
local StarterGui = game:GetService("StarterGui")

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local changeTextRE = ReplicatedStorage.ChangeText

local textBox = StarterGui.SurfaceGui.TextBox

changeTextRE.OnServerEvent:Connect(function(player, text)
	
	local filteredText = text --> make sure to filter it before sending it!
	textBox.Text = filteredText
	
	changeTextRE:FireAllClients(filteredText)
end)

still doesn’t work, here the player gui’s text box is still empty after entering the text through the textbutton



again, no errors popped

I’m not exactly sure how your project is structured and i don’t have enough information to know what’s wrong. both examples i showed work but you might have to change something to make it work exactly for your case.

Here is the file of my working example. Try to find what’s different in your place and debug it.
TextBox.rbxl (60.0 KB)

1 Like

thanks! i’ll try to implement your system into my game. though it might be until next week when i can work on this again (due to exams), i’ll let you know how it works out. again, thanks so much for your help!

1 Like

okay, i just tested it, and it worked! i am able to enter text and it also appears on the server side. i can also read with another script to use in another system. thank you so much for your help!

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