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
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
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.