Wait for player response (chat)

Hi there!

I am looking for a way to get a chatted response from a player. For example, I let my bot say “Hi there, what is your nickname?”. It should then wait for the player to respond and continue executing.

The reason I’m asking it here is because when I make an event listener player.Chatted, it stops the rest of the script (Duh).

Anyone else got an idea how I can achieve this?

Thanks a lot! :slight_smile:

1 Like

It shouldn’t stop the script. What’s your code?

I mean, it will keep on executing, won’t it? Let me just test something very quickly.

Yes. Unless you make your bot smarter. Just only make the bot say “Hi there” when the player chats. Add the code to say other things when the player sends their name. If you’re sending it through a remote event it should be a piece of cake.

I need the bot to start the interaction.

Make the bot start the interaction then. You can still hook its other responses to a remote event.

Not sure if this is what you’re looking for. Both of these lines have different use cases and will halt any further code execution until the player either chats or says a specific message.

local Players = game:GetService("Players")
local thisPlayer = Players:FindFirstChild("marketmanager1")

--thisPlayer.Chatted:Wait() -- Wait for the player to send a message (can be anything)
--repeat until thisPlayer.Chatted:Wait() == "MSG" -- Wait for the player to send a specific message
1 Like
local Players = game:GetService("Players")
local thisPlayer = Players:FindFirstChild("marketmanager1")
thisPlayer.Chatted:Wait() -- Wait for the player to send a message (can be anything)

That seems to be what I’m looking for. How’d I get the message content here? :slight_smile:

local Message = thisPlayer.Chatted:Wait()

Using :Wait() on an event returns the arguments, so in this case, “Message” will be whatever the player said.

1 Like

Thanks!

1 Like