ScreenGui change position randomly

I have made a script where the ImageLabel changes position randomly with a fading in and out effect

Now it works but not how i wanted it to…
It sometimes changes the position while the fading in and out effect is being played
i want that it fades in at random times, and stays there for a random time, and fades out, then changes its position, and the cycle repeats itself.

Now heres my code, i tried everything but i couldn’t get it to work:

local guiElement = script.Parent

local function Move()
	while true do
		
		guiElement.Position = UDim2.new(math.random(), 0, math.random(), 0)
		
		for transparency = 0, 1, 0.01 do
			guiElement.ImageTransparency = transparency
			wait(0.007)
		end

		wait(math.random(1, 6))

		for transparency = 1, 0, -0.01 do
			guiElement.ImageTransparency = transparency
			wait(0.007)
		end

		wait(math.random(1, 6))
	end
end

Move()

I’d be very happy if you guys would help me!

Move gui element position part of the script after the transparency change.

1 Like

Thank you, and i also put an if statement to check if the transparency is 1 so then it only changes position, now it works perfectly

1 Like