Problems with stopping a loop (typewriter effect)

Try using ZonePlus. What’s probably happening is one of your player parts exit (performing the TouchEnded function) while all your other body is in the part. Because of that, it will run the Touch and TouchEnded multiple times, probably causing issues. ZonePlus simply checks if a player entered an area and goes from there. The documentation is here, if you want to learn more.

I replaced your code with ZonePlus. Tell me if anything changes or if you have any new issues. If you have more issues, I’m sure @VexorgIRL will help out!

IMPORTANT EDIT: This is the code you started the thread with. Things may have been modified.

local dialogueDebounce = false
local progressDebounce = false

local TypewriterModule = require(script.ModuleWriter)
local writeSound = script.Typewriter

local RS = game:GetService("ReplicatedStorage")
local EffectEvent = RS:WaitForChild("ConstructionSoundBlur")

local ZonePlus = require(RS:WaitForChild("ZonePlus") -- you dont need to have the module in ReplicatedStorage of course, it's just an example

local zone = Zone.new(script.Parent)

zone.playerEntered:Connect(function(player)
	local HasAcceptedYet = player:WaitForChild("ConstructionFolder").HasAcceptedYet
	local TypewriterDebounce = player:WaitForChild("ConstructionFolder").TypewriterDebounce
	if HasAcceptedYet.Value == false then
		if dialogueDebounce == false then
			local gui = player.PlayerGui:WaitForChild("EventDialogue")
			TypewriterDebounce.Value = true
			gui.Holder.Visible = true
			gui.Holder:TweenPosition(UDim2.new(0.5, 0, 0.73, 0), "In", "Linear", 1, true, nil)
			dialogueDebounce = true
			task.wait(1)
			gui.Holder.Header.Visible = true
			gui.Holder.DialogueText.Visible = true
			task.wait(1)
			local yesButton = gui.Holder.Yes
			local noButton = gui.Holder.No
			local object = gui.Holder.DialogueText
			if TypewriterDebounce.Value == true then
				TypewriterModule.typeWrite(object, "Yo! I'm Frank, the Construction Manager.", writeSound.TimeLength, writeSound)
				wait(2)
				TypewriterModule.typeWrite(object, "We are tasked with constructing a new building, but we won't finish in time!", writeSound.TimeLength, writeSound)
				wait(3)
				TypewriterModule.typeWrite(object, "We need your help constructing the building.", writeSound.TimeLength, writeSound)
				wait(2)
				TypewriterModule.typeWrite(object, "Do you accept this offer?", writeSound.TimeLength, writeSound)
				wait(0.5)
				yesButton.Visible = true
				noButton.Visible = true
				yesButton:TweenPosition(UDim2.new(0.162, 0, 1.214, 0), "In", "Linear", 0.5, true, nil)
				noButton:TweenPosition(UDim2.new(0.562, 0, 1.214, 0), "In", "Linear", 0.5, true, nil)
			end
			wait(0.5)
			noButton.MouseButton1Click:Connect(function()
				gui.Holder.DialogueText.Text = ""
				yesButton:TweenPosition(UDim2.new(0.162, 0, 3, 0), "In", "Linear", 0.2, true, nil)
				noButton:TweenPosition(UDim2.new(0.562, 0, 3, 0), "In", "Linear", 0.2, true, nil)
				wait(0.2)
				yesButton.Visible = false 
				noButton.Visible = false
			end)
			yesButton.MouseButton1Click:Connect(function()
				yesButton:TweenPosition(UDim2.new(0.162, 0, 3, 0), "In", "Linear", 0.2, true, nil)
				noButton:TweenPosition(UDim2.new(0.562, 0, 3, 0), "In", "Linear", 0.2, true, nil)
				wait(0.2)
				yesButton.Visible = false
				noButton.Visible = false
				TypewriterModule.typeWrite(object, "Thanks for your help!", writeSound.TimeLength, writeSound)
				wait(2)
				TypewriterModule.typeWrite(object, "To manage your tasks, click on the orange star button.", writeSound.TimeLength, writeSound)
				wait(2)
				TypewriterModule.typeWrite(object, "That's all, good luck!", writeSound.TimeLength, writeSound)
			end)
		end
	elseif HasAcceptedYet.Value == true then
		if progressDebounce == false then
			local gui = player.PlayerGui:WaitForChild("ConstructionGui")
			local sound = player.PlayerGui.HUD.Sidebar.Container.Construction.LocalScript.ClickSound
			gui.Holder.Visible = true
			gui.Holder:TweenPosition(UDim2.new(0.5, 0, 0.5, 0), "In", "Elastic", 1, true, nil)
			EffectEvent:FireClient(player, 15)
			task.wait(1)
			progressDebounce = true
		end
	end
end)


zone.playerExited:Connect(function(player)
	if player:FindFirstChild("PlayerGui") then
		local HasAcceptedYet = player:WaitForChild("ConstructionFolder").HasAcceptedYet
		local TypewriterDebounce = player:WaitForChild("ConstructionFolder").TypewriterDebounce
		if HasAcceptedYet.Value == false then
			if dialogueDebounce == true then
				local gui = player.PlayerGui:WaitForChild("EventDialogue")
				gui.Holder.DialogueText.Text = ""
				gui.Holder.Header.Visible = false
				gui.Holder.DialogueText.Visible = false
				gui.Holder.Yes.Visible = false
				gui.Holder.No.Visible = false
				TypewriterDebounce.Value = false
				gui.Holder:TweenPosition(UDim2.new(0.5, 0, 1.5, 0), "In", "Linear", 1, true, nil)
				task.wait(1)
				gui.Holder.Visible = false
				dialogueDebounce = false
			end
		elseif HasAcceptedYet.Value == true then
			if progressDebounce == true then
				local gui = player.PlayerGui.ConstructionGui
				local sound = player.PlayerGui.HUD.Sidebar.Container.Construction.LocalScript.ClickSound
				gui.Holder:TweenPosition(UDim2.new(0.5,0,1.5,0), 'InOut', 'Elastic', 1)
				EffectEvent:FireClient(player, 0)
				task.wait(0.8)
				progressDebounce = false
			end
		end
	end
end)

(I didn’t test any of this code. Too much of a hassle to recreate! Hopefully it works.)

2 Likes