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)
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.
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.
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?