How do I make a textlabel display the player's username?

  1. What do you want to achieve?
    A text label that displays the local player’s username (I basically want to put a text on a gravestone that displays the players username)

  2. What is the issue?
    I tried scripting it myself but I’m quite unexperienced so I couldn’t manage to, also the yt tutorials I watched were useless.

  3. What solutions have you tried so far?
    There are some similar topics I found but none of them helped me really.

This is what I tried and also found on tutorials… I even dont know if Im atleast on the right path

local player = game.players.localplayer
text = script.parent
text.text = player.name

Thanks for your help! Looking forward to your replies

5 Likes

If the script is inside of the TextLabel, then just;

script.Parent.Text = game:GetService("Players").LocalPlayer.Name
1 Like

If you want the DisplayName Simply change .Name to .DisplayName (refer to 1Luca)

1 Like

It seems like you’re on the right path, but there are some minor corrections to make in your code. LIke how getting the name of the Player would be with a capital P instead of a lowercase.

Here’s an example:

local player = game.Players.LocalPlayer
local textLabel = script.Parent -- Assuming the TextLabel is a child of the script

-- Set the Text property of the TextLabel to the player's username
textLabel.Text = player.Name
2 Likes

lua is case sensitive lua is case sensitive

As @Kokonamiii said use text.Text and use a local script if you don’t already

Well thats kinda what I tried and didnt work

I tried putting this script both in localscript and script but still doesnt work

1 Like

Yeah right but it’d be useless to change it to display name when I cant even get the players name on the text yet

Use a normal script, with RunContext set to client. That’s a property under the script.

have u tried printing the name in order to see where the problem is?

You are doing things right but there are some mistakes like:

game.players.localplayer should be game.Players.LocalPlayer with the correct capitalization and If you’re dealing with a TextLabel, then the Text property (with a capital T) should be used to change its displayed text.

  1. game.players.localplayer should be game.Players.LocalPlayer with the correct capitalization.
  2. If you’re dealing with a TextLabel, then the Text property (with a capital T) should be used to change its displayed text.
-- Assuming this is a LocalScript

local Players = game:GetService("Players")

local localPlayer = Players.LocalPlayer
local textLabel = script.Parent

textLabel.Text = localPlayer.Name

2 Likes

Good stuff, but also here: Use a normal script, with RunContext set to client. That’s a property under the script.
The use-case here is for a gravestone, which is highly likely to be a descendant of the workspace. Normal local scripts don’t run there, but RunContext = Client ‘regular’ scripts do.

4 Likes

Can you perhaps screenshot the section of the Explorer where you’re doing this?

1 Like

Ur right it worked like that, thanks alot!

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.