How to get a players Display Name

I’m trying to make a System Message when a player dies, using there display name and if they don’t have one then for the message to use there username.

It works fine without trying to use there display name for the death message, but once I tried doing it with a display name it just won’t make the message at all.

local function welcome(playerName)
		i = " died"
		
	local name = {}
	if playerName.DisplayName ~= nil then
		name = playerName
	elseif playerName.DisplayName == nil then
		name = playerName.DisplayName
	end
	
	
	game.StarterGui:SetCore('ChatMakeSystemMessage', {

		Text = name.DisplayName..i;

		Font = Enum.Font.SourceSansBold;

		Color = textColor.Color;

		FontSize = Enum.FontSize.Size24;

	})

	end
end

remoteEvent.OnClientEvent:Connect(welcome)

Is playerName a Player Instance? If so, just use the DisplayName property; If the player doesn’t have one, the property is the same as their username:

https://create.roblox.com/docs/reference/engine/classes/Player#DisplayName

2 Likes

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