Beginner Tutorial #1: How To Make a Part or NPC Chat!

Hello, developers! :slight_smile:

Today, I want to show you how to make a part or NPC chat!
image
A talking part!

image
Cool talking noob!

This tutorial requires a beginner amount of knowledge of scripting such as variables, services, loops, and tables.

Step 1: Create a part in workspace and insert a script. Delete the default code.

Step 2: Get the Chat service. This service is mainly used for handling the built-in chat system, but us developers can use it, too! Today, we’ll be using the built-in :Chat() function. Type this in your script:

local ChatService = game:GetService("Chat")

Step 3: You can customize this however you want and I’ll explain how to in a minute. For the sake of this tutorial though, we will create a table of phrases that the part/NPC will be able to say. Under where you previously defined the ChatService, create a new table named Phrases and create a few strings of text you want the part or NPC to say.

--Create as much text as you want!
local phrases = {
	"Hello!",
	"Welcome to the game!",
	"ROBLOX is the best game ever!"
}

Step 4: Create a while do loop that runs every four seconds and chooses a random piece of text from our phrase table.

while task.wait(4) do
	local RandomPhrase = phrases[math.random(1 , #phrases)] --Chooses a random string from our phrases table.  It will randomize between a number as low as 1 and a maximum of however many strings are in our table.
end

Step 5: Make the part/NPC chat. To do this, inside of our while loop, we will fire the :Chat() method of the ChatService.

This function takes three parameters:

  1. partOrCharacter: Instance – The part to display a chat bubble above.
  2. message: string – The text to appear in the chat bubble.
  3. color: Enum.ChatColor – The color of the chatted message. (White is recommended as other colors sometimes make the bubble and/or text invisible when other colors overlap with it on screen.)

ChatService:Chat(workspace.Part, RandomPhrase, Enum.ChatColor.White)

Final code:

local ChatService = game:GetService("Chat")

local phrases = {
	"Hello!",
	"Welcome to the game!",
	"ROBLOX is the best game ever!"
}

while task.wait(4) do
	local RandomPhrase = phrases[math.random(1 , #phrases)]
	ChatService:Chat(workspace.Part, RandomPhrase, Enum.ChatColor.White)
end

Playtest this and see if it works!

If you have an NPC you want to make talk, change workspace.Part to NPC.Head.

If you enjoyed this tutorial, please let me know by liking it! If there is anything you think I could do to improve or change, feel free to let me know. I’m new to creating tutorials, so feedback is always appreciated! You can also let me know if there is anything you would like to know how to create! I will try to help you!

Have a wonderful day! :slight_smile:

~Kittylitterking123

24 Likes

If this topic has helped anybody, please let me know or if there is anything you would like to know how to make, tell me and I can try to help you! Have a great day! :slight_smile:

1 Like

This tutorial is great. I’ve already made something similar but took a look anyway and this was greatly explained and I hope we see more tutorials by you!

1 Like

Thank you so much for the reply! Your words mean so much to me! I plan on doing more tutorials soon, but I’m not sure on what. Any suggestions?

1 Like

I’m not sure. You could make a tutorial explaining in depth the difference between scripts, and what each script use is for, and ways to use each script effectively. I can help with this aswell if you’d like

1 Like

I will definitely do that! I feel like that’s something that could really help people. I feel like a lot of tutorials don’t take the time to explain everything clearly and as simple as possible so everyone can understand. Right now, I’m going to make beginner tutorials to fully grasp how to make them, as I’ve only made one before.

Yes, you can help with it if you like!

1 Like

Awesome. If you have discord we can talk about it there and get a tutorial out soon.

1 Like

I don’t have a Discord currently, but we could talk through DMs.

Alright. I’ll make sure to use dev forum more then

1 Like

Does this work with TextChatService? Some tutorials don’t seem to work with it.

1 Like

Yes, you can customize this to work with TCS.

New tutorial out now! :smiley:
Beginner Tutorial #2: How To Make A Jumpscare! - Resources / Community Tutorials - Developer Forum | Roblox

1 Like

thanks bro !! u are amazing !!! loved it :fire::fire::fire:

1 Like

Thank you so much! I’m so glad you enjoyed it! Your words warmed my heart!