Automatic updating username UI system

Hello, I’m Sarah

Tonight I’ve been trying to get a feature working to automatically update player names on a UI going by their userId however, I am not much of a experienced programmer. I know the basics however, I’m still learning. This simple task has turned into a 2 hour project for me. I’ve been searching the wiki and tutorials to try figuring this out for myself with no luck so I may as well turn to here in hopes someone knows what they’re doing for this for guidance. Most likely I’ve been writing this completely wrong this whole time. 3D modelling is honestly my strong point, not so much with Lua lol

Here’s my current code:

local ui = script.Parent
local player = game:GetService("Players")

if player.UserId == 178755574 then
	ui.Text = player.Name
end

This the UI I’ve been trying to complete:


The idea is to have each name run off the players userId so if anyone is to update their username on the Roblox site, it would automatically update in new servers. This is to save me the time of having to go back and edit their name each time.

If anyone is will awake at this hour to help, it would be much appreciated! :slight_smile:

1 Like

Not entirely sure if this is what you are searching for, but GetNameFromUserIdAsync will return the players name from a given Id, thus don’t need to keep changing labels, can just insert the user Ids

And in your case

ui.Text = game.Players:GetNameFromUserIdAsync(178755574)

Would give the players name. That way, if their name changes, the UI text will always match their current name

2 Likes

Thank you, someone actually beat you to the punch on Discord and was able to help the same way you were suggesting above. I tried getting this to work earlier but I was writing it wrong the first time round. lol

1 Like