How would I be able to make an image label move on a surface GUI?

One day when I was playing Tower Defense Simulator, I saw this:


The images were moving so I decided to try to make one for myself, but failed.

How would I be able to make the image tween on a surface GUI and make it go back and forth?

I of course don’t know how Tower Defense Simulator has done it but what you want to achieve can be done using the TweenService. I recommend reading the article about it, there are some code examples in the article that can help you.

Tower Defense Simulator moves the image label around.

What I tried is this:

local movingimage = script.Parent

while true do
	movingimage:TweenPosition(UDim2.new(0, -250, 0, 0),"Out","Quint",5,true)
	wait(1)
	movingimage:TweenPosition(UDim2.new(0, 0, 0, 0),"Out","Quint",5,true)
end

Tower Defense Simulator moves the image label around.

What I tried is this:

local movingimage = script.Parent

while true do
	movingimage:TweenPosition(UDim2.new(0, -250, 0, 0),"Out","Quint",5,true)
	wait(1)
	movingimage:TweenPosition(UDim2.new(0, 0, 0, 0),"Out","Quint",5,true)
end
1 Like

Using the TweenService you can make it loop without using a while/for loop but if you insist on using TweenPosition then you need to have a wait after both tweens. Your 4th argument is the time it takes to tween which you set as 5, so why do you wait only 1 second before doing the second tween? On top of that you also need to give the second tween time to complete.

So your code should look more like this:


while true do
	movingimage:TweenPosition(UDim2.new(0, -250, 0, 0),"Out","Quint",5,true)
	wait(5)
	movingimage:TweenPosition(UDim2.new(0, 0, 0, 0),"Out","Quint",5,true)
	wait(5)
end
2 Likes

I didn’t know that it required that wait(5)
Thank you!

2 Likes