Let's look at two scenarios.
1.) Using a local script
2.) Using a regular script
One issue with your code is that you can't use LocalPlayer and .PlayerAdded in the same script due to the simple fact that one only works in server-scripts
and one only works in localscripts
.
If this is a localscript, we can make the code to:
1 | local plr = game.Players.LocalPlayer; |
3 | repeat until plr.ChildAdded:wait().Name = = "PlayerGui" |
4 | plr.PlayerGui.PhoneGui.Menu.Owner.Text = name; |
In a regular script, we can do the following:
1 | game.Players.PlayerAdded:connect( function (plr) |
3 | plr.PlayerGui.PhoneGui.Menu.Owner.Text = name; |