Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to fire a function when a string of words is entered in the chatbox?

This may sound like a rather stupid question, I used to know this but now I've forgotten

If I wanted to print "Hi" when I press a button I would just type:


Button.Touched:Connect(function()

print("Hi")

end)


But, if I wanted the game to print "Hi" when the player types and enters something in the chat box, how would I implement such a thing?

2 answers

✓ Accepted answer

There's an event for that.

It's Chatted event and it's fired when a player uses the chat bar.

Here's an example on how to use it:

game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(message) --message he sent is the first parameter
		print(player.Name.." says: "..message)
		--do stuff
	end)
end)

1 comment

0

Yes, this is exactly what I was looking for, thanks

Chat box? Do you mean like Text box or the chat?

If it's Text box, use this code:

TextBox.Changed:Connect(function(property) -- When the properties of the textbox changed
    if property == "Text" then -- If the property is text then
        print("hi") -- hi
    end
end

If it's chat, use this code:

game.Players.PlayerAdded:Connect(function(player) -- When a player joined
    player.Chatted:Connect(function(message) -- When the player chatted
        print("hi") -- hi
    end)
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.