Responsive UI with TweenService

I have been trying to make a responsive UI for the main menu of my game where when your mouse hovers over the ImageButton, it slightly moves upward.
I’ve written a pretty simple script for this, but for some reason, it does not work and I can’t lay my finger on the issue correctly. If anyone has an idea on how to make this work, please let me know :slight_smile:
Here is the code:

local TweenService = game:GetService('TweenService')
local gui = script.Parent

local tweenInfo = TweenInfo.new(
	.5,
	Enum.EasingStyle.Quart
)

local goal = {
	gui.Position.Y.Scale == -0.025,
}

local playTween = TweenService:Create(gui, tweenInfo, goal)

gui.MouseEnter:Connect(function()
	playTween:Play()
end)

image

1 Like

Y is read only, there are two equal signs, and you’re doing gui.Position instead of Position. You could do something like so to fix this:

local goal = {
	Position = UDim2.new(0.1, 0, -0.025, 30)
}

Note that you might need to change the numbers in the UDim2. That was just guesswork on what it could be for your setup.

Also, I would like to ask- did you not see the output window? Surely it would’ve told you about these things to hint you to the solution…

1 Like

Thank you, it works fine, I will tweak the values a bit to adjust it.

Yes, I had it open, although I did not see any error or warning, which I found peculiar.

1 Like

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