How do you make a smooth 2D gui movement system?

Hi!
Im trying to make a 2D game with Guis, i have made a movement system my self, but
its not smooth, i mean it like it just snaps in to the next position.
Here the game if you want to see what i mean:

Gui Game Test

here is the code:

local debounce = false
game:GetService("UserInputService").InputBegan:Connect(function(inputObject, gameProcessedEvent)
	if inputObject.KeyCode == Enum.KeyCode.W then
		if not debounce then
			debounce = true
			script.Parent.Position = script.Parent.Position +  UDim2.new(0,0,-0.1)
		end
		wait(0.3)
		debounce = false
	end 
end)

is there a way i can make it with TweenService and animations?
Thanks!
AlexFuzzy21

1 Like

Use TweenService, it is the most optimal solution.

yes, i know, but how can you make it so, it moves more to the side , but not go to the set position and stay there?

you mean something like recoil ?

i mean like something like this:

https://www.roblox.com/games/7118222392/2d-gui-game

when you move to a side it does a smooth animation, and it can still got to the side you went.
i dont know how to do it with TweenService, that what i meant.

oh so basically you can do it like this:
You play the tween
Then you wait for the tween to finish (Use Tween.Completed:Wait())
Then you replace the GUI position with the destination position