Npc custom diolog

I’m tying to make a npc dialog but there’s one problem that the npc dialog don’t talk.

local say = ("Hello Adventure")

script.Parent.ClickDetector.MouseClick:Connect(function(playergui)
	playergui.PlayerGui["npc system"].NpcChatGui.NpcName.Text = script.Parent.Name
	playergui.PlayerGui["npc system"].NpcChatGui.Enabled = true
	for i, v in pairs(say) do
		for i = 1, string.len(v) do wait(0.005)
			playergui.PlayerGui["npc system"].NpcText.Text = string.sub(v, 1, i)
		end
		wait(string.len(v) / 10)
	end
	playergui.PlayerGui["npc system"].NpcChatGui.Enabled = false
end)

You’re doing a in pairs on say, which isn’t a table. You’re probably getting an error in there somewhere that says table expected got string or something like that. Try something like this instead.

local say = "Heyyyyyy what's up."

script.Parent.ClickDetector.MouseClick:Connect(function(playergui)
	playergui.PlayerGui["npc system"].NpcChatGui.NpcName.Text = script.Parent.Name

	for i = 1, #say do
		playergui.PlayerGui["npc system"].NpcChatGui.NpcText.Text = string.sub(say, 1, i)
		task.wait(0.045) 
	end
end)

there’s no error but the script doesn’t work

Is that your entire script? Just tested my revision and it works fine for me.

If there are no errors this probably means one or more if checks in your script dont get the right value. Try putting prints before and after if statements to see which ones stop the script.

the script kinda work but it only one letter only instead of “Hello”
Screenshot 2022-03-24 205230

this the script now

local say = "Hello"

script.Parent.ClickDetector.MouseClick:Connect(function(playergui)
	playergui.PlayerGui["npc system"].NpcChatGui.NpcName.Text = script.Parent.Name
	playergui.PlayerGui["npc system"].NpcChatGui.Enabled = true
	for i = 1, #say do
		playergui.PlayerGui["npc system"].NpcChatGui.NpcText.Text = string.sub(say, 1, i)
		    task.wait(5) 
			playergui.PlayerGui["npc system"].NpcChatGui.Enabled = false
		end
	end)
1 Like

You’re doing task.wait(5) in the loop, and then continuing to disable the GUI here. What that means every single letter it takes five seconds to show the next, and then you disable the gui after, meaning you won’t be able to see the rest of it. Do the following instead if you’d like to disable it after, just make sure to keep it out of the original loop that is controlling the letters appearing on the screen.

local say = "Heyyyyyy what's up."

script.Parent.ClickDetector.MouseClick:Connect(function(playergui)
	playergui.PlayerGui["npc system"].NpcChatGui.NpcName.Text = script.Parent.Name

	for i = 1, #say do
		playergui.PlayerGui["npc system"].NpcChatGui.NpcText.Text = string.sub(say, 1, i)
		task.wait(0.045) 
	end
task.wait(5)
playergui.PlayerGui["npc system"].NpcChatGui.Enabled = false
end)

Also it might help in the future to name stuff more efficiently, although it’s really up to you, it just looks a lot cleaner. :slight_smile:

1 Like
local say = "Hello"

local ChatGui = playergui.PlayerGui["npc system"].NpcChatGui

script.Parent.ClickDetector.MouseClick:Connect(function(playergui)
	ChatGui.NpcName.Text = script.Parent.Name
	ChatGui.Enabled = true
	for i = 1, #say do
		ChatGui.NpcText.MaxVisibleGraphemes = i
		task.wait(0.05) 
		ChatGui.Enabled = false
	end
end)

Its recommended to use the MaxVisibleGraphemes property for typewriter effect. Why?

1 Like

the script works and I will like to say thx you and all for helping me