Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
oggy521 72
6 years ago

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

Log in to vote
0
Answered by 6 years ago

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)
0
Yes, this is exactly what I was looking for, thanks oggy521 72 — 6y
Ad
Log in to vote
0
Answered by
SCP774 191
6 years ago

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)

Answer this question