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!
You can use Player.DisplayName
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
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??
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…
Nothing printed But I did just realize this in the Output
DisplayName is not a valid member of Model "Workspace.devforum_helper"
Yup it’s definitely not humanoid
I just realized you’ve pasted player instead of character
game.Players:GetPlayerFromCharacter(hit.Parent).DisplayName
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?