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

Printing a TextBox Text?

I've tried to make this script many times but It never works! I don't know what is wrong with my code. Here it is:

local TextBox = game.StarterGui.ScreenGui.TextBox

local TextButton = game.StarterGui.ScreenGui.TextButton

TextButton.MouseButton1Click:Connect(function)
print(TextBox.Text)
	
end

2 comments

0

Thats because youre accessing the starterGui, not the playerGui.

0

so textbox would look something like this: local TextBox = game:GetService("Players").LocalPlayer.PlayerGui.ScreenGui.TextBox if this is a local script

2 answers

you are modifying/accessing the StarterGui, everything thats inside the startergui gets cloned into the PlayerGui of a player. So if a player changes something then the changes happen in the PlayerGui not in the StarterGui. So you ll have to access the PlayerGui instead.

the PlayerGui is part of the player. like this Player.PlayerGui

see PlayerGui vs StarterGui

in this case that would be (localscript)

local player = game.Players.LocalPlayer

local TextButton = player.PlayerGui.ScreenGui.TextButton

You forgot to put a () at the end of :Connect(function() and you put it as StarterGui. I hope this helps

local TextBox = game.Players.LocalPlayer.PlayerGui.ScreenGui.TextBox

local TextButton = game.Players.LocalPlayer.PlayerGui.ScreenGui.TextButton

TextButton.MouseButton1Click:Connect(function()
	print(TextBox.Text)
end

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