Help with creating NPC talking system

What I want to achieve, is have working NPCs that talk. To clarify, talking like in story games, or like this.

The issue, is, I’m just a beginner programmer, and I don’t really know how to script this. I want to get it to work, but if I really can’t, should I make something simpler, or keep trying.

I have looked for solutions just about anywhere I know. I’ve found multiple tutorials, but those either have code that isn’t explained very well, or don’t fit what I need, and are buggy.

I just need help on explaining how, not an entire script written.

Tutorials I have found:
a. This tutorial is difficult, and hard to edit for me. I also don’t really know about the code.
b. This works well, but I want mine to be click-activated, and theirs is also buggy.

Code so far:

I’m sorry if it’s bad or anything.
It obviously doesn’t work, and it’s kind of a mix of my own thing, and a tutorial.
My workspace:
image
ModuleScript:

local module = {
	Dummy = {Page1 = {"Testing Page1, line1", ""}, Page2 = {"", "Testing Page2, Line2"}},
	
}

return module
Code

Code so far:

local player = game.Players.LocalPlayer
local npcs = workspace.NPCs:GetChildren()
local uis = game:GetService("UserInputService")
local DialogueUI = player.PlayerGui:WaitForChild("DialogueUI")
local bg = DialogueUI.Background
local Dialogue = require(script:WaitForChild("Dialogue"))
local CurrentPage = 1
local CurrentNPC = ""
local Click = CurrentNPC.TalkPart

local function typing(text1, text2)
	bg.TextLabel1.Text = ""
	bg.TextLabel2.Text = ""

	DialogueUI.Enabled = true

	local page = CurrentPage
	local npc = CurrentNPC
	for i = 1, string.len(text1), 1 do
		if DialogueUI.Enabled == false or page ~= CurrentPage or npc ~= CurrentNPC then break end
		if string.sub(text1, i, i) ~= " " then
			bg.TextLabel1.Text = string.sub(text1, 1, i)
			wait(0.05)
		end
	end
	wait(0.3)
	for i = 1, string.len(text2), 1 do
		if DialogueUI.Enabled == false or page ~= CurrentPage or npc ~= CurrentNPC then break end
		if string.sub(text1, i, i) ~= " " then
			bg.TextLabel2.Text = string.sub(text2, 1, i)
			wait(0.05)
		end
	end
end



Click.MouseClick:Connect(function(key, chat)
	if chat then return end
	
		if player.PlayerGui.DialogueUI.Enabled == false then--Start Dialogue
		--	CurrentNPC = button.Parent.Parent.Name
			bg.NPCName.Text = CurrentNPC
			CurrentPage = 1

		
		

			typing(Dialogue[CurrentNPC]["Page1"][1], Dialogue[CurrentNPC]["Page1"][2])
		end

end)

I know it’s terrible, and doesn’t work, I just need some pointers on which direction to go.

Also, should I use a ModuleScript to store all the code?

I don’t really know if doing something is too much to ask for, for a programmer like me.

If you need extra info on what I'm trying to get it to look like

Things I’m trying to get it to do:
Cannot talk to multiple NPCs at once
Ability to talk with multiple “pages”
Organized

Thank you!

2 Likes

I would recommended learning the basics of scripting before you start this, but you can always follow the tutorial and learn from the script you’ve made.

I know a bit about scripting, like Modules, and stuff, but yeah, I would agree.

For tutorials, or anything, what should I see, or learn from? (specifically for the NPC thing)

(Sorry to ask more, but can you give any pointers on what to do with the script, or where to start?)

Youtube is a great way to find what your looking for, alternatively you can use the Developer Hub I mainly use this if I have forgotten something and just need a quick refresher on how it works. Another great way is looking through free models and learning how they work.

There are many post talking about getting into scripting on here, so I would recommend checking them out.

2 Likes

There are 2 ways to do this. One is simple but has less options and the next has plenty of options.
The first is to use the dialogue part and add dialogue choices and do that(from what I’ve done max 2)
The next is to use a script to wait X seconds and then have a chat bubble appear above there head.(if you want I can send you the script later)

1 Like

I don’t think you read the whole thing, but here’s an example of what I want it to be like: How To Make A NPC Dialogue System In Roblox - YouTube.

Hello, I’ve open sourced an Chat Bot feature perhaps you might find it useful.

Note: This system uses actual Neural Network Technology.

Here is the link;

Here is a preview video, Let me know if you found this useful and or need help.

There are games already using this feature. I’ll also be working on a module to embed more features to this via roblox [Dialog features with actuan NN will be coming soon].

It might help a little, but I don’t think you really get what I’m trying to do.

I’m trying to make a talking NPC, that is similar to How To Make A NPC Dialogue System In Roblox - YouTube.

An AI thing isn’t really what I need.

Although your chat bot scripts are pretty complicated so I’m assuming you know a lot. Could you give me some pointers on where to go, like what to do with my script, or a explanation?

If you could also give some tips on editing the scripts in the tutorial, or something, it would help me out a lot!

Yeah sure, Sure thing let me look at what you have so far.

1 Like

It’s in the post, but here it is again:
(This is a direct copy of the main post’s code thing)

If you need extra info on what I'm trying to get it to look like

Things I’m trying to get it to do:
Cannot talk to multiple NPCs at once
Ability to talk with multiple “pages”
Organized

Code so far:

I’m sorry if it’s bad or anything, I just started scripting last month.
It obviously doesn’t work, and it’s kind of a mix of my own thing, and a tutorial.
My workspace:
image
ModuleScript:

local module = {
	Dummy = {Page1 = {"Testing Page1, line1", ""}, Page2 = {"", "Testing Page2, Line2"}},
	
}

return module

Also, should I use a ModuleScript to store all the code?

I don’t really know if doing something is too much to ask for, for a programmer like me.