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

A really quick question, its only 3 lines of code?

Asked by 6 years ago

I am trying to get a textLabel to say Welcome back (player name).

For some reason this code isnt working and I am a little lost as to why?

Anyone have any ideas

game.Players.PlayerAdded:connect(function(player)
    script.Parent.Text = "WELCOME BACK" .. player.UserID
end)

Thank you for your time :)

1 answer

Log in to vote
0
Answered by
RayCurse 1518 Moderation Voter
6 years ago

Because your script is a local script inside a gui, there is no need to wait for a player to enter because by the time the local script is running, it is assumed that the player exists. Instead of setting up a listener function to the PlayerAdded event, simply set the property of the LocalPlayer. The fixed code would look like this:

script.Parent.Text = "WELCOME BACK" .. game.Players.LocalPlayer.UserID

In addition you used the UserID property of the player and when judging from the welcome back text, you probably wanted to use the name. In that case, you simply set the Name property instead:

script.Parent.Text = "WELCOME BACK" .. game.Players.LocalPlayer.Name
Ad

Answer this question