TextBox.Text not transferring to TextLabel.Text

Hello, DevForum!

I’m trying to make my TextBox’s Text to copy over to my TextLabel’s Text (When I type something in the TextBox it transfers to the TextLabel after I click “Enter”)

I’ve tried many ways and none were working, this is my current script:

local InputBox = game.StarterGui.ScreenGui.InputBox
local OutputBox = game.StarterGui.ScreenGui.OutputBox

InputBox.FocusLost:Connect(function(PressedEnter)
	if PressedEnter then
		OutputBox.Text = InputBox.Text
	end
end)

image

I’ve tried looking through the devforum, and tried the scripts there, they didn’t work. I looked thorugh the devhub but it didn’t help either.

Thanks for reading!

3 Likes

.FocusLost would only do it if focus is lost change this too 2 separate functions and it should work.

1 Like

Use the Player’s PlayerGui instead of StarterGui, I assume this is that Localscript in your screengui, change it to this

local screenGui = script.Parent

local InputBox = screenGui.InputBox
local OutputBox = screenGui.OutputBox

InputBox.FocusLost:Connect(function(PressedEnter)
	if PressedEnter then
		OutputBox.Text = InputBox.Text
	end
end)

StarterGui only holds the guis that are replicated to each player’s playerGui, you need to reference the guis in their PlayerGui

3 Likes

Hey. You are referencing the elements in the startergui. Try doing that with the playergui.
Is this a LocalScript?

1 Like

Oh, thanks so much! I did not know there was a PlayerGui as I don’t see it in the explorer, I’m guessing it’s not direct. Again, thank you so much!

1 Like

Anytime! if you have anymore issues don’t be afraid to make another post!

And PlayerGui is a child of a Player Instance, so you can’t find it via the explorer unless you’re doing an ingame test.

I was originally going to send this

local Players = game:GetService("Players")

local player = Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
local screenGui = playerGui:WaitForChild("ScreenGui")

local InputBox = screenGui.InputBox
local OutputBox = screenGuiOutputBox

InputBox.FocusLost:Connect(function(PressedEnter)
	if PressedEnter then
		OutputBox.Text = InputBox.Text
	end
end)

But then I saw that the localscript is a child of the ScreenGui, so I made it simpler for you, but both do the same thing, one just uses the fact it’s already in the PlayerGui so it just uses indexing, and the other gets the PlayerGui and then references the ScreenGui

Also, the LocalPlayer property is only useable in Localscripts, using it in regular scripts will return nil/nothing

1 Like

Oh, thanks for explaining, very much appreciated!

2 Likes