Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Changing a TextLabel's Text Through a TextBox?

I am trying to make a smart board for my friend and I have run into multiple issues that I have solved using posts, but this one I can't find anything about. I am trying to change the smart boards text in a surfacegui through a textbox's text. Script so far (ignore the variable i disabled):

--local screen = script.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Screen
local screen = game.Workspace.Split.SmartBoard1.Screen
while true do
	screen.SurfaceGui.Text.Text = game.Players.LocalPlayer.PlayerGui.SurfaceGui.Frame.Words.Text
	wait(1)
end

I am using game.Workspace because my script is in PlayerGui due to SurfaceGui's not having text editable on unless they are in there. Any help is appreciated!

1 comment

0

You must use remote events and fire event from local script and then make server script that will change the text through the remote, if you dont understand i will post better explanation 

1 answer

✓ Accepted answer

So bassicaly what you do is put local script inside of the box and make it fire server event to server script, i will show you little example:

Local script in text box:

local event = game.ReplicatedStorage.RemoteEvent -- remote event
local runService = game:GetService("RunService") 
local text = script.Parent 
runService.RenderStepped:Connect(function()
	event:FireServer(text.Text) -- Sends text through remote event
end)

and server script:

local event = game.ReplicatedStorage.RemoteEvent
event.OnServerEvent:Connect(function(player, text) -- gets name of player who sent it and text from the textBox
	print(text) -- Prints text
end)

Hope it helps.

4 comments

0

If you want to send the text only when you click button then you make it similar but remove the service and make something like button.MouseButton1Click:Connect(function()

0

Would the server script just go anywhere?

0

Worked thx so much!

1

This is actually a horrible practice. You can simply just send the Text upon a .FocusReleased() signal of the TextBox. The event supplies an EnterPressed boolean that can be used a debounce for determining whether the person has set the Text by the return key. If you want to update live, add a listener through a :GetPropertyChangedSignal() listener.

This discussion is preserved as it was. New answers, comments, and votes are closed.