The Chatted script isn't printing in the output

Hello developers, I’m not sure why this isn’t working. Also, I want to clarify that I want the script to be on the client-side and not on the server-side. The script’s parent is StarterPlayerScripts. Please let me know if you find any issues. Thank you.

Script:

local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()


player.Chatted:Connect(function(msg)
	if msg:lower() == "Hello" then
		print("CHAT")
		
	else
		print("NO CHAT")
	end
end)

Any feedback would be appreciated.

1 Like

I’m pretty sure Hello is not lowercase :sweat_smile:

Use:

local player = game:GetService("Players").LocalPlayer

player.Chatted:Connect(function(message)
	if string.lower(message) == "hello" then
		print("CHAT")
	else
		print("NO CHAT")
	end
end)

local character = player.Character or player.CharacterAdded:Wait()
--???
2 Likes

I copied and pasted your code, played the game, and typed ‘hello’, but it didn’t print anything. I’m not sure what’s wrong…

Where did you put the script? It seems that it isn’t running.

The local script is located inside of StarterPlayerScripts.

Can you try print() on the first line?

1 Like

I tried adding a ‘print’ statement in the first line of the script, which worked correctly and printed ‘hello’. However, I’m still unable to get the chat script to work. Do you have any ideas on what might be causing the issue?

I’m not sure player.Chatted works in a local script.

Try this in a server script:

game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(message)
		if string.lower(message) == "hello" then
			print("CHAT")
		else
			print("NO CHAT")
		end
	end)
end)

I thought that the ‘Chatted’ event should work in a local script, and I even saw some videos where it worked. I’m not sure what went wrong with my implementation, but the script you provided seems to work on the server-side. I was hoping to get it working on the client-side, but thank you for your help!

I tried the exact same code, and I found out the problem is likely because TextChatService’s ChatVersion is set to TextChatService. Try switching it to LegacyChatService.

(Remember to change the “Hello” to lowercase)

I’m not sure what you mean. Could you please explain further, and also can, you tell me how I can make the necessary changes?

In the lower parts of the explorer, there’s a service called TextChatService. You can select it, and in properties, set the ChatVersion to LegacyChatService.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.