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
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