Med Written By MrSprinkleToes

Make NPC Talk Created on: 09-08-2019

Make an NPC or part speak random phrases at a specified interval!

Making an NPC Speak

By MrSprinkleToes

Before we begin...

Hello! Welcome to my tutorial. Today you will learn how to make an NPC (or any part) say random phrases, which are stored in a table. Now let's begin!

Step one: The table.

First, you must create a table containing the phrases you want the NPC to speak. Simply create a table containing multiple strings, each string a different phrase.


`lua
`

Step two: An infinite loop.

Simple, just create an infinite while loop with a few seconds wait in between.


`lua
`

Step three: Fetching a random phrase.

Now you just need to use math.random() to fetch a random phrase.


`lua
`

Step four: Finally, make the part / NPC chat the phrase!

Not very hard! Simply use the service "Chat" and call the :Chat() function, providing these three parameters:

  1. partOrCharacter (Instance)
  2. message (string)
  3. color (ChatColor, Enum.ChatColor)


`lua
`

And that's all!

Congratulations, you've done it! Now using the above code we put together, the specified part (or character) will chat every 5 seconds one of the phrases placed in the table "phrases". You can change the wait(number) to anything you'd like, and you can change up the phrases too!

The color Enum.ChatColor.White makes the chat bubble look like a regular chat bubble, however there are different options. Those include:

  • Enum.ChatColor.Blue
  • Enum.ChatColor.Green
  • Enum.ChatColor.Red
  • Enum.ChatColor.White

Happy scripting!

Med Written By MrSprinkleToes

See MrSprinkleToes's profile on Roblox

Discussion