Help getting player name

Hello, I need to get the name of all the players online, make sure that if in the chat I have written the name of the player then it shows a print ("Hello" ..player.name)

Example:

if chatmsg == "PlayerNameHere" then
    for index, playerName in ipairs(player) do
    print("Player name: "..player.Name)
    end 
end

I need to do that if the message written in the chat is the name of any online player in my game then make a print with their name, how could i do that? :frowning:

2 Likes
if chatmsg == "PlayerNameHere" then
	for index, playerName in ipairs(player) do
		print("Player name: "..tostring(chatmsg))
	end 
end
1 Like

I need to do that if in the chat the name of the player who is online in my game is written then a print appears with the name of the player that has been written

For example:

chat → /PlayerName

output:
print ("The player name is ..." .. player.Name)

How could i do that? :frowning:

1 Like

When you say “online”, do you mean in that particular server, or do you mean in all of the servers?

1 Like

i mean the players that are connected in the game that I am playing (in my same game and server) ;-;

1 Like
local p = game.Players:FindFirstChild(tostring(chatmsg))
if p then
	for index, playerName in ipairs(player) do
			print("Player name: "..tostring(chatmsg))
		end
	end 
1 Like

Using and editing the code that Roblox gave:

local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(Player)
    Player.Chatted:Connect(function(message)
    	for i,Player2 in pairs(Players:GetPlayers()) do
			if message == '/' .. Player2.Name then
		    	print("The player name is ..." .. Player2.Name)
	    	end
    	end
	end)
end)
1 Like

in spanish: eso funcionaria si pongo por ejemplo /MatiasHarders al escribir en el chat? :scream:

1 Like

In spanish: sí, funciona con todos los nombres de los jugadores que estén en el servidor.
PD: es mucho mĂĄs cĂłmodo hablar asĂ­ xd

1 Like

In spanish: Muchisimas gracias @SOTR654 :smiley:
In English: Thanks you a lot :smiley:

1 Like

De nada, feliz de ayudar ^ - ^
You’re welcome, happy to help ^ - ^

1 Like