While loop not working properly

soo im trying to make a script that makes a small effect for some text in the gui. im using while loops to make it so that it runs infinitely, but none of the code runs. here it is:

local txt = script.Parent
while true do
	print("started")
	wait(1.6)
	local txt2 = txt:Clone()
	txt2:FindFirstChild("LocalScript"):Destroy()
	txt2.Position = UDim2.new(txt2.Position.X.Scale, txt2.Position.X.Offset + 15, txt2.Position.Y.Scale, txt2.Position.Y.Offset)
	wait(.2)
	txt2.Position = UDim2.new(txt2.Position.X.Scale, txt2.Position.X.Offset, txt2.Position.Y.Scale, txt2.Position.Y.Offset + 15)
	wait(.2)
	txt2.Position = UDim2.new(txt2.Position.X.Scale, txt2.Position.X.Offset, txt2.Position.Y.Scale, txt2.Position.Y.Offset - 15)
	wait(.1)
	txt2:Destroy()
	print("done")
end

the output is like this:

12:25:11 -- started
12:25:11 -- done
12:26:17 -- started
12:26:17 -- done

what ive already tried was to change the localScript to a server script. did not work.
tried changing the wait() to task.wait() did not work
i also dont see any errors so please help

you didn’t parent the txt2:Clone()

local txt = script.Parent
while true do
	print("started")
	wait(1.6)
	local txt2 = txt:Clone()
	txt2:FindFirstChild("LocalScript"):Destroy()
        txt2.Parent = txt.Parent -- change to anything 
	txt2.Position = UDim2.new(txt2.Position.X.Scale, txt2.Position.X.Offset + 15, txt2.Position.Y.Scale, txt2.Position.Y.Offset)
	wait(.2)
	txt2.Position = UDim2.new(txt2.Position.X.Scale, txt2.Position.X.Offset, txt2.Position.Y.Scale, txt2.Position.Y.Offset + 15)
	wait(.2)
	txt2.Position = UDim2.new(txt2.Position.X.Scale, txt2.Position.X.Offset, txt2.Position.Y.Scale, txt2.Position.Y.Offset - 15)
	wait(.1)
	txt2:Destroy()
	print("done")
end

oh yeah i forgot to parent it thanks!!

1 Like

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