How to check if player said any persons name?

If I joined a game, and someone said “Hi 1BL1ZZARD”, how could i make it print something? It’s not for me in specifics, if someone else said “Hi soniciscool209056”, it would print the same thing. I tried using this:

local Message = string.lower(message)
    if string.find(Message, Players.FindFirstChild) then
         print("hi")
    end
end
1 Like

So something like this?

nono, just in general, if blantantly said your name, it should print “hi”, so “ScriptedPoptartz”, it will print “hi” in output. they need to be in game though.

game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(message)
		if game.Players:FindFirstChild(message) then
			print("hi")
		end
	end)
end)

local Message = string.lower(message)
for _, player in pairs(game.Players:GetPlayers()) do
if string.find(Message, string.lower(player.DisplayName) then
print(“hi”)
end
end

This loops through all players. If the message contains their display name it prints “hi”
If you want to use usernames then do ,name not .displayname

If the message matched several usernames it would print “hi” more than once. If you don’t want that just use break to exit the loop the first time a player is found

3 Likes

doesn’t work sorry :frowning: thanks for trying to help though

This wouldn’t work unless you just say just the player’s name.
Also I don’t see you looping anywhere.

To sum up everything, this will work:

game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(text)
		local message = string.split(text, " ")
		
		for i = 1, #message do
			if game.Players:FindFirstChild(i) then
				print("hi")
				break -- this can be removed if you want it to detect multiple names.
			end
		end
	end)
end)

Brief explanation: When a player chats, it splits up the chat and looks for a name in Players, and if found will print ‘hi’ and stop, or keep going.

Of course it won’t work, because your not doing it in a function. Check my updated message for it to work.

do i place this in a local script? i was trying to do this all in a server script

1 Like

That script is either server or client! Works best/should be in a server though.

tysm it worked! before it didn’t tho

this works too, i had to slightly modify it to work tho

1 Like