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?
local displayname = ... -- desired display name
for _, v in pairs(game.Players:GetPlayers()) do
if v.DisplayName == displayname then
-- your code here.
end
end
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.