Gui/Loop Not Stopping

I’ve been trying for 30 minutes to make work this but it doesn’t work

Currently making an achievement gui work here’s a screenshot:


But my loop doesn’t work
here’s the script (local script in starter gui):

local db = false

game.Workspace.Map.idk:WaitForChild("L").Touched:Connect(function()
	if db == false then
		db = true
		
		script.Parent.AchievementGui.Enabled = true

		script.Parent.AchievementGui.AchievementFrame.CornerImage.AchievementText.Text = "Well, Dont fall!"

		while true do
			wait(.1)
			script.Parent.AchievementGui.AchievementFrame.BackgroundTransparency -= 0.1
			if script.Parent.AchievementGui.AchievementFrame.BackgroundTransparency == 0.6 then
				break
			end
		end
		while true do
			wait(.1)
			script.Parent.AchievementGui.AchievementFrame.CornerImage.ImageTransparency -= 0.1
			if script.Parent.AchievementGui.AchievementFrame.CornerImage.ImageTransparency == 0 then
				break
			end
		end
		while true do
			wait(.1)
			script.Parent.AchievementGui.AchievementFrame.CornerImage.Achievement.TextTransparency -= 0.1
			script.Parent.AchievementGui.AchievementFrame.CornerImage.AchievementText.TextTransparency -= 0.1
			if script.Parent.AchievementGui.AchievementFrame.CornerImage.Achievement.TextTransparency == 0 and script.Parent.AchievementGui.AchievementFrame.CornerImage.Achievement.TextTransparency == 0 then
				break
			end
		end
		wait(5)
		while true do
			wait(.1)
			script.Parent.AchievementGui.AchievementFrame.BackgroundTransparency += 0.1
			wait(.1)
			if script.Parent.AchievementGui.AchievementFrame.BackgroundTransparency == 1 then
				break
			end
		end
		while true do
			wait(.1)
			script.Parent.AchievementGui.AchievementFrame.CornerImage.ImageTransparency += 0.1
			if script.Parent.AchievementGui.AchievementFrame.CornerImage.ImageTransparency == 1 then
				break
			end
		end
		while true do
			wait(.1)
			script.Parent.AchievementGui.AchievementFrame.CornerImage.Achievement.TextTransparency += 0.1
			script.Parent.AchievementGui.AchievementFrame.CornerImage.AchievementText.TextTransparency += 0.1
			if script.Parent.AchievementGui.AchievementFrame.CornerImage.Achievement.TextTransparency == 1 then
				break
			end
		end
		script.Parent.AchievementGui.Enabled = false
	end
end)

here’s another screenshot to show what’s wrong
robloxapp-20240202-2213429.wmv (1.8 MB)
As you can see the first loop isn’t stopping

H E L P

if you need more infos ask me!

Why are there so many loops, and why are you using loops in the first place?
Wouldn’t tweens be more convenient?
If there is a reason you are using loops instead then it might help to use a coroutine or a seperate thread for each loop, both for performance and to easily stop each loop with task.cancel().

I have heard about tweens but idk what they are and that they used for this how can i update my script ?

Tweens aren’t that hard to use, it may look that way though so I’ll write you a template instead of just pasting a link to the tween documentation.

local TweenService = game:GetService("TweenService")
local Time = TweenInfo.new(1)
--------------------------------------------------------
local Item = script.Instance
local Properties = {
	PropertyName = 1,
	SecondProperty = 1
}
--------------------------------------------------------
local tween = TweenService:Create(Item,Time,Properties)
--------------------------------------------------------
wait()
tween:Play()

In your case,
“Item” should be “script.Parent.AchievementGui.AchievementFrame”
“PropertyName” should be “BackgroundTransparency”
and so on.
Hope this helps!

how can i make it stop at 0.6 backgroundtransparency ?
and do this code is good for the moment ?

local db = false
local TS = game:GetService("TweenService")

game.Workspace.Map.idk:WaitForChild("L").Touched:Connect(function()
	if db == false then
		db = true
		
		local Time = TweenInfo.new(.1)
		
		local Item = script.Parent.AchievementGui.AchievementFrame
		
		local Properties = {
			PN1 = "BackgroundTransparency",
			PN2 = "ImageTransparency",
			PN3 = "TextTransparency"
		}
		
		script.Parent.AchievementGui.Enabled = true

		script.Parent.AchievementGui.AchievementFrame.CornerImage.AchievementText.Text = "Well, Dont fall!"
		
		local tween = TS:Create(Item,Time,Properties{1})
		wait()
		tween:Play()
		
		script.Parent.AchievementGui.Enabled = false
	end
end)

It would be

local Properties = {
	BackgroundTransparency = 0.6
}