How would I go about grabbing a players username and displaying it on a play menu?

Hello everyone!

I am currently building a screenGUI player menu where the player can spawn, select teams and view other information and I was wondering,

How would I grab a players username and display it in “Username”.

image

Note: I just guessed this has something to do with scripting, if it doesn’t please flag or let me know so I can change topic.

4 Likes

If you could show us the explorer of your UI I could definetly help you

1 Like

Do something like this in your code:

text.Text = "Hi" .. player.Name .. "Welcome to North Valley Academy"
2 Likes

How you could do this is do,

Game.Player.PlayerAdded and then get the player which is provided in the () and do local PlayerName = plr.Name and then change the texxt of the username.

1 Like

Or something which could be quicker and more effient is if u just want the player to see it u could just do in a local script find the local player and then do player.Name like what @exp_lol123 gave on the UI.

(if it is a diffrent text label tfor the username then u could just do Player.Name then doing what @exp_lol123 and puting it inside the string with the rest of the stuff.

1 Like

Uhh using the PlayerAdded event within a server script (or just a Script) it would be changed for everyone, if you didn’t go over the gui of just one player. Anyway, I would recommend to just do something like this:

local player = game:GetService("Players").LocalPlayer

GUIElement.Text = "" .. player.Name -- this will do the text and the name.

And this would be all my guy, literally.

1 Like

The welcome text label is the label I am trying to control.
image

1 Like

Add a local script and write:

local Player = game.Players.LocalPlayer
local Welcome = script.Parent.Welcome

Welcome.Text =  " | Hi," .. Player.Name
1 Like

This is for when you touch a part the text appears:

local part = *Your Part here*

part.Touched:Connect(function(hit)

if hit.Parent:FindFirstChild("Humanoid") then

local player = game.Players:GetPlayerFromCharacter(hit.Parent)

player.PlayerGui.Your Gui Name here.TextLabel.Visible = true

player.PlayerGui.Your Gui Name here.TextLabel.Text = "Hi "..player.Name.." welcome to North Valley Academy"

end

end)

and for joining a game:

game.Players.PlayerAdded:Connect(function(player)

player.PlayerGui.Your Gui Name here.TextLabel.Visible = true
player.PlayerGui.Your Gui Name here.TextLabel.Text = "Hi "..player.Name.." Welcome to North Valley Academy"

end
end)
1 Like
local player = game.Players.LocalPlayer
(Identify the text label).Text = player.Name

I believe works?

1 Like

Hi everyone, thanks for all the suggestions. Either way, I have tried them all and can’t seem to get the to work even when fixing the location for the script to find the label. Is it something to do with text label settings? Should the text label be empty or have some sort of place holder there?

1 Like

Edit: There was a mistake in the code then I fixed it

It has to be a localscript and it should be under “MainMenuBackground” like this:
image

Then also the script should say this:

local PlayerService = game:GetService("Players")
local LocalPlayer = PlayerService.LocalPlayer
local WelcomeText = script.Parent.Welcome

WelcomeText.Text = ("👋| Hi, "..LocalPlayer.Name.." ! Welcome to")
3 Likes

Thank you! This works great now.

2 Likes

You could use a hacky, and a simple method

  local player = game:GetService("Players")
  local txt = script.Parent.Welcome
  txt.Text = string.gsub(txt, "USERNAME", player.Name) -- You could set the text to "Hi, USERNAME"