Strange glitch instantly bringing dialogue to the end

For some reason whenever the button is pressed for the first time CurrentDialogue instantly goes to “7ending” please help

local DialogueGui = script.Parent
local DialogueSequence = DialogueGui.DialogueSequence
local Main = DialogueGui["Dialogue Box"]

local CurrentDialogue = 2

local clickedend = false

local canpress = true

local function endchat()
	
	print(CurrentDialogue)
	
	game:GetService("TweenService"):Create(Main, TweenInfo.new(1, Enum.EasingStyle.Quint, Enum.EasingDirection.InOut), {Position = UDim2.new(0.5, 0,1.5, 0)}):Play()

	wait(1)

	game.ReplicatedStorage.CameraFade:FireServer(false)
	script.Parent:Destroy()
	game.Players.LocalPlayer.PlayerGui.NPCChatUi.AnabellaBuildboard.Tom.Visible = true
	
end
	
Main.DialogueBox.Text = DialogueSequence.One.Value


Main.ContinueButton.MouseButton1Click:Connect(function()	
	
			
		canpress = false
		
	if CurrentDialogue == 2 then
		
		Main.DialogueBox.Text = DialogueSequence.Two.Value
		CurrentDialogue = 3
		Main.ContinueButton.Text = "No"
		Main.Yes.Visible = true
		
	end
	
	if CurrentDialogue == 3 then

		Main.DialogueBox.Text = DialogueSequence.Two.No.Value
		CurrentDialogue = 4
		Main.ContinueButton.Text = "Next"
		Main.Yes.Visible = false
		
	end
	
	if CurrentDialogue == 4 then
		
		Main.DialogueBox.Text = DialogueSequence.Four.Value
		CurrentDialogue = 5
		
	end
	
	if CurrentDialogue == 5 then

		Main.DialogueBox.Text = DialogueSequence.Five.Value
		CurrentDialogue = 6
		Main.ContinueButton.Text = "No"
		Main.Yes.Visible = true

	end
	
	if CurrentDialogue == 6 then

		Main.DialogueBox.Text = DialogueSequence.Five.No.Value
		CurrentDialogue = "7ending"
		Main.ContinueButton.Text = "Walk Away"
		Main.Yes.Visible = false

	end
	
	
	if CurrentDialogue == "7ending" then
		
	endchat()

	end
	
	
	
	if CurrentDialogue == 7 then

		Main.DialogueBox.Text = DialogueSequence.Seven.Value
		CurrentDialogue = 8
		Main.ContinueButton.Text = "Why?"

	end
	
	if CurrentDialogue == 8 then

		Main.DialogueBox.Text = DialogueSequence.Eight.Value
		CurrentDialogue = 9
		Main.ContinueButton.Text = "Alr ig"

	end
	
	if CurrentDialogue == 9 then
		
		endchat()

		
	end
		

	end)



Main.Yes.MouseButton1Click:Connect(function()	

	if CurrentDialogue == 3 then

		Main.DialogueBox.Text = DialogueSequence.Two.Yes.Value
		CurrentDialogue = 4
		Main.ContinueButton.Text = "Next"
		Main.Yes.Visible = false

	end
	
	if CurrentDialogue == 6 then

		Main.DialogueBox.Text = DialogueSequence.Five.Yes.Value
		CurrentDialogue = 7
		Main.ContinueButton.Text = "No Worries"
		Main.Yes.Visible = false

	end

end)

Never mind I just changed em to elseif instead

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.