Two AnimateText scripts overlap eachother

Hello, i am making a UI only game called DON’T TOUCH THE BUTTON and i have an issues with some scripts that draw text. There are 2 scripts, the first one is enabled when the player enters the game. It’s a script that animates a text box saying the rules of the game and when it ends it dissapears. the second one appears when the player touches the button for the first time, blaming and threatening the player for touching the button.

The first issue is that the 2 scripts are for the same TextLabel, so if you spam the button, the two lines that the codes display overlap eachother.

And the second issue when the line starts the text becomes visible and when it ends the text becomes insible, it’s the same for the two scripts. so if you click the button mid sentence of the text displaying and changing it for another line, the lines overlap again.

I tried to make the line stop when another is enabled, destroying the script or dissapearing the text but nothing works.

Here are the two scripts:

SCRIPT ONE

local Button = script.Parent.Parent.TextButton
local scripty = game.StarterGui.ScreenGui2.TextLabel.LocalScript
local player = game.Players.LocalPlayer

local function AnimateText(Text)
	for i = 1, #Text, 1 do
		script.Parent.Text = string.sub(Text, 1 ,i)
		wait(0.03)
	end
end

while true do
	AnimateText("Hello. i am the narrator!")
	wait(4)
	AnimateText("All you gotta do in this game is to")
	wait(2)
	AnimateText("NOT TOUCH THE BUTTON")
	wait(4)
	AnimateText("Have fun!")
	wait(0.5)
	script.Parent.Visible = false
	script.Disabled = true
	script:Destroy()
	
end

if player.WaitForChild("leaderstats").WaitForChild("Clicks").Value >= 1 then
	script.Parent.Visible = false
	script.Disabled = true
	script:Destroy()
end

SCRIPT TWO

local Button = script.Parent.Parent.TextButton
local scripty = script
local player = game.Players.LocalPlayer


Button.MouseButton1Click:Connect(function(hit)

	print("buttonTouched")
	

local function AnimateText(Text)
	for i = 1, #Text, 1 do
		script.Parent.Text = string.sub(Text, 1 ,i)
		wait(0.03)
	end
end

	while true do
		script.Parent.Visible = true
		AnimateText("Why did you do that.")
	wait(2)
	AnimateText("if you do that again i will break you ")
	wait(4)
		script.Parent.Visible = false
	        script.Disabled = true
	        script:Destroy()
		end
end)
if player.WaitForChild("leaderstats").WaitForChild("Clicks").Value >= 2 then
	script.Parent.Visible = false
	script.Disabled = true
	script:Destroy()
end

this is how my StarterUi looks like:
image

And here’s how the game looks like:
image

I would appreaciate some help!

Maybe create a BoolValue that when something is enabled it is true and when not it’s false. Put it under ReplicatedStorage, so it’s easy to access. If that doesn’t work, try it with events, make a variable change when a specific event is fired.

But what would that value do? something like if value = true then script.destroy()? cuz script.destroy() or script.parent.visible = false arent working for my scripts.

When the value is true you could prevent it from happening, doing return, maybe.

something like: if button.clicks >= 1 then return AnimateText()?

Yea sure, that could work. (Making this text longer because of the 30 chxr minimum)

Return didn’t work, i think i could duplicate the textlabel, so i put the script one in the original textlabel and the script two in the duplicate, but i don’t know if that would “fix” my issues.

i gotta go, if you find something while i am gone, put it here. i will probably see it. bye