Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why won't this finding of a username work?

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)

5 comments

0

Take away the () near Username.

0

Tried that

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.

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.

0

Also, in the original script ,player.name should be player.Name.

1 answer

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.