How to break a loop after waiting

local Enemy = script.Parent

DYW = false
TTW = 10

while true do
	wait(0.7)
	Enemy.Position = Enemy.Position - UDim2.new(0,9,0,0)
	Enemy.Animation.Visible = true
	Enemy.ImageTransparency = 1
	Enemy.Position = Enemy.Position - UDim2.new(0,9,0,0)
	wait(0.7)
	Enemy.Animation.Visible = false
	Enemy.ImageTransparency = 0
	Enemy.Position = Enemy.Position - UDim2.new(0,9,0,0)
	wait(TTW)
	DYW = true

	if DYW == true then
		break
	end
end

So, this script doesn’t work, it breaks before the 10 seconds and any other ways I try don’t work as well. Any ideas?

It does? How can you tell? From what it looks like, you run wait(TTW) and then break on the first loop.
If you put print("finished") after the loop, it should print finished only after 11.4 seconds have passed.

Are you wanting to loop the code above wait(TTW) for 10 seconds? Because putting wait(TTW) and then a guaranteed break inside of the loop just causes the loop to pause for ten seconds and then exit.

Try this instead.

local TTW = 10
local start = tick()
while tick()-start < TTW do -- break if the time elapsed since `start` >= TTW
    -- the code you want to loop
end

What do you mean? Your code would wait more than 10 seconds before breaking.