Getting DisplayName doesn't work

Hello, I’m trying to get the displayname of a player with a TextBox, but it doesn’t work, and I don’t know how to do it correctly, here is the elements:

localscript

local plr = game:GetService("Players")
local rem = game.ReplicatedStorage.RemAdm:WaitForChild("Vel")
local click = script.Parent.Parent.Parent.Click

local usuar = script.Parent.InputUser.Boton
local display = script.Parent.InputDisplay.Boton

-- User  (this works) --
usuar.MouseButton1Click:Connect(function()
	click:Play()
	local user = plr:FindFirstChild(usuar.Parent.Text)
	local vel = script.Parent.InputVel.Text
	local salt = script.Parent.InputSalto.Text
	
	rem:FireServer(user,vel,salt)
end)

-- Display (This doesn't work) --
display.MouseButton1Click:Connect(function()
	click:Play()
	local disp = plr.LocalPlayer.DisplayName:FindFirstChild(disp.Parent.Text)
	local vel = script.Parent.InputVel.Text
	local salt = script.Parent.InputSalto.Text

	rem:FireServer(disp,vel,salt)
end)

and serverscript

local rep = game:GetService("ReplicatedStorage")
local remvel = rep.RemAdm.Vel

-- Vel y salto --

-- This works--
remvel.OnServerEvent:Connect(function(plr,user,vel,salt)
	local us = user.Character:FindFirstChild("Humanoid")
	us.WalkSpeed = vel
	us.JumpPower = salt
end)

-- and not this --
remvel.OnServerEvent:Connect(function(plr,disp,vel,salt)
	local us = disp.Character:FindFirstChild("Humanoid")
	us.WalkSpeed = vel
	us.JumpPower = salt
end)

Is there any way to get the displayname without any problem?

You’re trying to say

plr.LocalPlayer.DisplayName????

Instead just use LocalPlayer.

what are you trying to do with this line exactly?

wait, I think by plr that’s the game service players… just realized that.

Is trying to get the displayname of the player that was put in the textbox

You’re trying to reference a player’s character with their display name. That won’t work. Try using their real name.

It would be way safer to use the real name to find the player, and then in the server script get the display name.

let me explain to you.

you are using
plr.LocalPlayer.DisplayName to get the player’s display name

but why are you putting :FindFirstChild(disp.Parent.Text)

but is there any way to get the display in the same way as the username? Like Kohl’s admin
image

Well, you could loop through the players in game, to check the first player if they have a display name of the display name you’re trying to find,

But anyway else, no.

It is trying to get the text of the textbox, like this:
image

Something like this:

local displayname = ... -- desired display name

for _, v in pairs(game.Players:GetPlayers()) do
  if v.DisplayName == displayname then
    -- your code here.
  end
end

The thing about this method is that it will only get the first player that it finds

Sorry, I’m a spanish speaker, and I may not respond very well to posts

you can get the player’s displayname or username without using values.

if you want the username do:
local playername = game.Players.LocalPlayer.Name

if you want the displayname do :
local playername = game.Players.LocalPlayer.DisplayName

keep in mind these are local scripts and won’t work in normal scripts

1 Like

But you CANNOT use a display name to reference a player. You can’t say:

local player = game.Players.lol -- display name!!!!1
1 Like
local players = game:GetService("Players")

local function getPlayerByDisplayName(displayName : s) : player
	for _, player in ipairs(players:GetPlayers()) do
		if player.DisplayName:match("^"..displayName.."$") then
			return player
		end
	end
end

You just need a function similar to :FindFirstChild() and :GetPlayerByUserId() that’ll fetch a player instance based on the value of their DisplayName property.