Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Printing a TextBox Text?

Asked by 4 years ago

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
0
Thats because youre accessing the starterGui, not the playerGui. mixgingengerina10 223 — 4y
0
so textbox would look something like this: local TextBox = game:GetService("Players").LocalPlayer.PlayerGui.ScreenGui.TextBox if this is a local script mixgingengerina10 223 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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

Answer this question