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:
1 | local TextBox = game.StarterGui.ScreenGui.TextBox |
2 |
3 | local TextButton = game.StarterGui.ScreenGui.TextButton |
4 |
5 | TextButton.MouseButton 1 Click:Connect( function ) |
6 | print (TextBox.Text) |
7 |
8 | 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)
1 | local player = game.Players.LocalPlayer |
2 |
3 | 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
1 | local TextBox = game.Players.LocalPlayer.PlayerGui.ScreenGui.TextBox |
2 |
3 | local TextButton = game.Players.LocalPlayer.PlayerGui.ScreenGui.TextButton |
4 |
5 | TextButton.MouseButton 1 Click:Connect( function () |
6 | print (TextBox.Text) |
7 | end |