How would I get a players Display Name?s

Hello I have a TextLabel that says the players name, But I want it to say th players Display Name
If you have any Idea to help, its Appreciated!

1 Like

You can use Player.DisplayName

2 Likes

this is my code

ball = script.Parent
local att = ball:GetAttribute("LastTouch")
ball.Touched:Connect(function(hit)
	if ball:GetAttribute("LastTouch")==hit.Parent.DisplayName then return end
	if hit.Parent:FindFirstChildOfClass("Humanoid") then
		ball:SetAttribute("LastTouch", hit.Parent.DisplayName)
	end
	
end)

the thing is that I’m trying to make it so, I touch the ball, the attribute’s text is my displayname, it didnt work though

Humanoid’s have display names too. So try using humanoid.DisplayName

3 Likes
ball = script.Parent
local att = ball:GetAttribute("LastTouch")
ball.Touched:Connect(function(hit)
	if ball:GetAttribute("LastTouch")==hit.Parent.DisplayName then return end
	if hit.Parent:FindFirstChildOfClass("Humanoid") then
       local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		ball:SetAttribute("LastTouch", player.DisplayName)
	end
	
end)

Nah, I tried @Jenny1223im’s :GetCharacterFromPlayer but that didn’t work
So I tried

that didnt work also, anything wrong?

ball = script.Parent
local att = ball:GetAttribute("LastTouch")
ball.Touched:Connect(function(hit)
	if ball:GetAttribute("LastTouch")==hit.Parent.DisplayName then return end
	if hit.Parent:FindFirstChildOfClass("Humanoid") then
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		local hum = player:FindFirstChildOfClass("Humanoid")
		ball:SetAttribute("LastTouch", hum.DisplayName)
	end

end)

Try printing to see if it indeed works or not

I recommend using Player.DisplayName instead of the Humanoid.DisplayName could be changed by something else.

It didn’t work for him please read above

Replace the Player variable with just hit.Parent… Why are you redefining the character model when you already have it??

1 Like

It didn’t work for the previous code because Player was not defined properly.

But this is confusing. I wonder why it didn’t work…

1 Like

Nothing printed But I did just realize this in the Output

DisplayName is not a valid member of Model "Workspace.devforum_helper"

1 Like

Yup it’s definitely not humanoid

1 Like

I just realized you’ve pasted player instead of character

1 Like
game.Players:GetPlayerFromCharacter(hit.Parent).DisplayName
1 Like
if ball:GetAttribute("LastTouch")==hit.Parent.DisplayName then return end

What this if statement check? Check the player name is equal to the LastTouch value or check if it is player character?

1 Like