I’ve been working on a custom NPC dialogue but I’ve ran into an issue. For whatever reason, randomly it will start the dialogue back over to the start (sometimes even more than once). Im unsure on what could be causing this and have speculated for hours but to no prevail. Any help is very much appreciated!!!
I can provide more information if needed!
Local Script:
NOTE: The Dialogue Variable is a module script storing important info, such as the choices, the next line of dialogue, and etc.
local function NextDialogue(Dialogue, NPC)
if CurrentDialogue.Choices then --Checks if the current dialogue has choices
for i, v in pairs(CurrentDialogue.Choices) do --Goes through each choice
--Creates each and every choice button!
local ClonedTemplate = Template:Clone()
ClonedTemplate.Name = i
ClonedTemplate.Text = v.Text
ClonedTemplate.Parent = ChoicesFrame
TS:Create(ClonedTemplate, TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut), {BackgroundTransparency = 0, TextTransparency = 0}):Play()
wait(.1)
ClonedTemplate.Activated:Connect(function()
Current = CurrentDialogue.Choices[tonumber(ClonedTemplate.Name)].Next
ChatEvent:FireServer(player.Character, v.Text)
NextDialogue(Dialogue, NPC)
end)
end
end
if CurrentDialogue.Next then
LeaveButton:Destroy()
NextButton.Visible = true
ClickFadeIn:Play()
NextButton.Activated:Connect(function()
NextButton.Visible = false
Frame.BackgroundColor3 = ShadedColor
ClickFadeOut:Play()
--print(Current, CurrentDialogue)
print("Changing Current to "..CurrentDialogue.Next)
task.wait(.1)
Current = CurrentDialogue.Next
Frame.BackgroundColor3 = NormalColor
NextDialogue(Dialogue, NPC)
end)
end
Video: