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

Why won't this finding of a username work?

Asked by
cboyce1 40
9 years ago

I have a feeling I screwed up on Line 3 at the end. Can someone help me edit it? Thanks :)

game.Players.PlayerAdded:connect(function(player)
    Username = player.name
    game.Players.LocalPlayer.PlayerGui.PhoneGUI.Menu.Owner.Text = (Username)
end)
0
Take away the () near Username. EzraNehemiah_TF2 3552 — 9y
0
Tried that cboyce1 40 — 9y
2
Is this within a LocalScript? If so, that is your problem; According to the WIKI, the 'PlayerAdded' event does not work in a LocalScript anymore. TheeDeathCaster 2368 — 9y
0
If it's a regular script use player.PlayerGui.PhoneGUI.Menu.Owner.Text = Username. If it's a local script do game.Players.LocalPlayer.PlayerGui.PhoneGUI.Menu.Owner.Text = game.Players.LocalPlayer.Name and remove the PlayerAdded. EzraNehemiah_TF2 3552 — 9y
0
Also, in the original script ,`player.name` should be `player.Name`. duckwit 1404 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago

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:

local plr = game.Players.LocalPlayer;
local name = plr.Name;
repeat until plr.ChildAdded:wait().Name == "PlayerGui"
plr.PlayerGui.PhoneGui.Menu.Owner.Text = name;

In a regular script, we can do the following:

game.Players.PlayerAdded:connect(function(plr)
local name = plr.Name;
plr.PlayerGui.PhoneGui.Menu.Owner.Text = name;
end)
Ad

Answer this question