Label shows last join player name

Hi developers, we are creating a Welcome Label that shows the player name, the problem it’s that shows the name of the last player joins.

Here’s the script:

local welcomeLabel = Workspace.Cartel.SurfaceGui.TextLabel
local function updateWelcomeMessage(playerName)

local welcomeMessage = "Welcome " … playerName
welcomeLabel.Text = welcomeMessage
end

updateWelcomeMessage(game.Players.LocalPlayer.DisplayName)

game.Players.LocalPlayer.NameChanged:Connect(function(newName)
updateWelcomeMessage(newName)
end)

For more details here is the explorer.

3 Likes

Put this in scripting support if you need help with scripting


Where is this script, and is this a local script?

It’s local, we tried ServerScrip, PlayerScript

Use ``` to wrap your code rather >. Also NameChanged isn’t an event for Player. Did you mean smth like this?

local welcomeLabel = Workspace.Cartel.SurfaceGui.TextLabel

local function updateWelcomeMessage(playerName)
    local welcomeMessage = "Welcome " … playerName
        welcomeLabel.Text = welcomeMessage
    end
end

updateWelcomeMessage(game.Players.LocalPlayer.DisplayName)
local welcomeLabel = workspace:WaitForChild("Cartel").SurfaceGui.TextLabel

local function updateWelcomeMessage(playerName)
	local welcomeMessage = "Welcome " … playerName
	welcomeLabel.Text = welcomeMessage
end

updateWelcomeMessage(game.Players.LocalPlayer.DisplayName)
1 Like
local Players = game:GetService("Players")
local welcomeLabel = workspace.Cartel.SurfaceGui.TextLabel

local function updateWelcomeMessage(playerName)

	local welcomeMessage = "Welcome "..playerName
	welcomeLabel.Text = welcomeMessage
end

Players.PlayerAdded:Connect(function(plr)
	
	updateWelcomeMessage(plr.Name)
	
end)

Try it with a server script

put in Starter Player → Starter Player scripts

1 Like

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