When the player talks to one NPC everything is fine. Until you talk to another NPC the text from the last NPC is overlapping with the other one, I don’t want that
.
Examples:
Here is an example of talking to one NPC:

Here is an example of taking to anther NPC:


These are the scripts for the dialogue:
Local script:
--// SERVICES
local players = game:GetService("Players")
local replicatedStorage = game:GetService("ReplicatedStorage")
local runService = game:GetService("RunService")
--// VARIABLES
local plr = players.LocalPlayer
local hrp = plr.Character:WaitForChild("HumanoidRootPart")
local humanoid = plr.Character:WaitForChild("Humanoid")
local Events = replicatedStorage.Events
local SetObjectiveRE = Events.SetObjectiveEvent
local Map = workspace.Map
local NPCs = Map.NPCs
local NPC1 = NPCs.NPC1
local NPC2 = NPCs.NPC2
local NPC3 = NPCs.Fisher
local NPC1Prompt = NPC1.Torso.DialoguePrompt
local NPC2Prompt = NPC2.Torso.DialoguePrompt
local NPC3Prompt = NPC3.Torso.DialoguePrompt
local MainFrame = script.Parent.MainFrame
local Button1 = MainFrame.Button1
local Button2 = MainFrame.Button2
local dialogueMod = require(script:WaitForChild("Dialogue"))
local Triggered1 = false
local Triggered2 = false
local triggered3 = false
local completedObjective1 = false
local completedObjective2 = false
--// CODE
runService.Heartbeat:Connect(function()
if Triggered1 then
Button1.TextButton.MouseButton1Click:Connect(function()
dialogueMod.CloseButton()
dialogueMod.Activated("Hello!", plr.DisplayName, 0.1)
dialogueMod.Activated("Hello, "..plr.DisplayName.."!", "NPC", 0.1)
dialogueMod.Activated("You will go through universes collecting artifacts throughout this adventure of a lifetime..", "NPC", 0.05)
dialogueMod.Activated("This universe is called 'Test Place' it is the very first universe you will explore!", "NPC", 0.05)
dialogueMod.Activated("Also make sure you grab every coin in each room!", "NPC", 0.08)
dialogueMod.Activated("Rise for this expedition!", "NPC", 0.1)
dialogueMod.closeDialogue()
humanoid.WalkSpeed = 16
hrp.Anchored = false
if completedObjective1 == false then
completedObjective1 = true
SetObjectiveRE:FireServer("1. ???")
end
task.wait(1)
SetObjectiveRE:FireServer("1. Make sure to collect coins!")
task.wait(2)
NPC1Prompt.Enabled = true
Triggered1 = false
end)
Button2.TextButton.MouseButton1Click:Connect(function()
dialogueMod.CloseButton()
dialogueMod.Activated("Goodbye!", plr.DisplayName, 0.1)
dialogueMod.Activated("Goodbye..", "NPC", 0.1)
dialogueMod.closeDialogue()
task.wait(0.5)
humanoid.WalkSpeed = 16
hrp.Anchored = false
if completedObjective1 == false then
completedObjective1 = true
SetObjectiveRE:FireServer("1. ???")
end
task.wait(1)
SetObjectiveRE:FireServer("1. Make sure to collect coins!")
task.wait(2)
NPC1Prompt.Enabled = true
Triggered1 = false
end)
end
if Triggered2 then
Button1.TextButton.MouseButton1Click:Connect(function()
dialogueMod.CloseButton()
dialogueMod.Activated("Hey there!", plr.DisplayName, 0.1)
dialogueMod.Activated("Hello, "..plr.DisplayName.."!", "NPC", 0.1)
dialogueMod.Activated("Sorry about the mess..", "NPC", 0.05)
dialogueMod.Activated("What are you doing here?", "NPC", 0.1)
dialogueMod.Activated("I dont think your supposed to be here..", "NPC", 0.1)
dialogueMod.Activated("Anyway, I have this special gem for you!", "NPC", 0.1)
dialogueMod.closeDialogue()
humanoid.WalkSpeed = 16
hrp.Anchored = false
if completedObjective2 == false then
completedObjective2 = true
SetObjectiveRE:FireServer("1. ???")
end
task.wait(3)
NPC2Prompt.Enabled = true
Triggered2 = false
end)
Button2.TextButton.MouseButton1Click:Connect(function()
dialogueMod.CloseButton()
dialogueMod.Activated("Farewell..", plr.DisplayName, 0.1)
dialogueMod.Activated("bye.. :(", "NPC", 0.1)
dialogueMod.closeDialogue()
task.wait(0.5)
humanoid.WalkSpeed = 16
hrp.Anchored = false
if completedObjective2 == false then
completedObjective2 = true
SetObjectiveRE:FireServer("1. ???")
end
task.wait(3)
NPC2Prompt.Enabled = true
Triggered2 = false
end)
end
if triggered3 then
Button1.TextButton.MouseButton1Click:Connect(function()
dialogueMod.CloseButton()
dialogueMod.Activated("Hey", plr.DisplayName, 0.1)
dialogueMod.Activated("Welcome, I am the fisher!", "Fisher", 0.1)
dialogueMod.Activated("You can sell the fish to me", "Fisher", 0.1)
dialogueMod.Activated("Talk to me with the fish in your hand to sell me the fish!", "Fisher", 0.1)
dialogueMod.closeDialogue()
humanoid.WalkSpeed = 16
hrp.Anchored = false
task.wait(3)
NPC3Prompt.Enabled = true
triggered3 = false
end)
Button2.TextButton.MouseButton1Click:Connect(function()
dialogueMod.CloseButton()
dialogueMod.Activated("Goodbye", plr.DisplayName, 0.1)
dialogueMod.Activated("See you soon..!", "Fisher", 0.1)
dialogueMod.closeDialogue()
humanoid.WalkSpeed = 16
hrp.Anchored = false
task.wait(3)
NPC3Prompt.Enabled = true
triggered3 = false
end)
end
end)
NPC1Prompt.Triggered:Connect(function(player)
Triggered1 = true
if completedObjective1 == false then
completedObjective1 = true
SetObjectiveRE:FireServer("Completed..")
end
NPC1Prompt.Enabled = false
hrp.Anchored = true
humanoid.WalkSpeed = 0
dialogueMod.Activated("...", "NPC", 0.1)
dialogueMod.Button("Hello!", "Goodbye..")
end)
NPC2Prompt.Triggered:Connect(function(player)
Triggered2 = true
if completedObjective2 == false then
completedObjective2 = true
SetObjectiveRE:FireServer("Completed..")
end
NPC2Prompt.Enabled = false
hrp.Anchored = true
humanoid.WalkSpeed = 0
dialogueMod.Activated("...", "NPC", 0.1)
dialogueMod.Button("Hey there!", "Farewell..")
end)
NPC3Prompt.Triggered:Connect(function(player)
triggered3 = true
NPC3Prompt.Enabled = false
hrp.Anchored = true
humanoid.WalkSpeed = 0
dialogueMod.Activated("...", "Fisher", 0.1)
dialogueMod.Button("Hey", "Goodbye..")
end)```
Module script:
```local ts = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
local DialogueGui = script.Parent.Parent
local DialogueBox = DialogueGui:WaitForChild("MainFrame")
local DialogueText = DialogueBox:WaitForChild("TextBox")
local DialogueName = DialogueBox:WaitForChild("NameBox")
local DialogueButton1 = DialogueBox:WaitForChild("Button1")
local DialogueButton2 = DialogueBox:WaitForChild("Button2")
local sound = script.Parent.Talk
local dialogue = {}
local function writeText(text: string, name: string, interval: number)
DialogueName.TextLabel.Text = name
-- DialogueText.TextLabel.MaxVisibleGraphemes = 0
DialogueText.TextLabel.Text = ""
for i = 1,#text,1 do
DialogueText.TextLabel.Text = string.sub(text,1,i)
task.wait(interval)
end
--for i = 1, utf8.len(text) do
-- if sound and sound:IsA("Sound") then sound:Play() end
-- -- DialogueText.TextLabel.MaxVisibleGraphemes += 1
-- DialogueText.TextLabel.Text = string.sub(text,1, i)
-- task.wait(interval)
--end
end
local function removeText()
DialogueText.TextLabel.Text = ""
end
local function openDialogue()
DialogueBox.Visible = true
DialogueText.TextLabel.Text = ""
ts:Create(DialogueBox, tweenInfo, {Position = UDim2.new(0.5, 0, 0.825, 0)}):Play()
task.wait(1)
end
function dialogue.closeDialogue()
ts:Create(DialogueBox, tweenInfo, {Position = UDim2.new(0.5, 0, 1.25, 0)}):Play()
task.wait(1)
DialogueBox.Visible = false
DialogueText.TextLabel.Text = ""
DialogueName.TextLabel.Text = ""
DialogueButton1.TextLabel.Text = ""
DialogueButton2.TextLabel.Text = ""
DialogueButton1.Visible = false
DialogueButton1.Interactable = false
DialogueButton2.Visible = false
DialogueButton2.Interactable = false
end
function dialogue.Button(buttontxt1, buttontxt2)
DialogueButton1.Visible = true
DialogueButton1.Interactable = true
DialogueButton2.Visible = true
DialogueButton2.Interactable = true
DialogueButton1.TextLabel.Text = buttontxt1
DialogueButton2.TextLabel.Text = buttontxt2
end
function dialogue.CloseButton()
DialogueButton1.Visible = false
DialogueButton1.Interactable = false
DialogueButton2.Visible = false
DialogueButton2.Interactable = false
DialogueButton1.TextLabel.Text = ""
DialogueButton2.TextLabel.Text = ""
end
function dialogue.Activated(text, name, interval)
openDialogue()
writeText(text, name, interval)
task.wait(1)
end
return dialogue```
Please help :sob: