Button when hovered tween service wont work

  1. What do you want to achieve? Keep it simple and clear!
    button tween service when hovered
  2. What is the issue? Include screenshots / videos if possible!
    tween servcie not changing when hovered

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

local TweenService = game:GetService("TweenService")
local button = script.Parent

local tweenInfo = TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
local originalSize = button.Size
local originalRotation = button.Rotation

button.MouseEnter:Connect(function()
	local sizeTween = TweenService:Create(button, tweenInfo, {Size = originalSize + Vector3.new(0.1, 0.1, 0)})
	sizeTween:Play()
	local rotationTween = TweenService:Create(button, tweenInfo, {Rotation = originalRotation + Vector3.new(0, 0, 6)})
	rotationTween:Play()
end)

button.MouseLeave:Connect(function()
	local sizeTween2 = TweenService:Create(button, tweenInfo, {Size = originalSize})
	sizeTween2:Play()
	local rotationTween2 = TweenService:Create(button, tweenInfo, {Rotation = originalRotation})
	rotationTween2:Play()
end)
1 Like

I think the issue comes from it playing multiple times, instead try and use a debounce.

A debounce works as follows:

local db = false

First we set it to false, now we have to check each time if it is false then we want to continue if not we dont, so we can do 2 things.
Either inside a function we can return, so cancel the function basically.

if db then return end
...

or we can have an if statement

if not db then
   ...
end

Now after that, we’ll insert the code in the ... spot, but we first have to set the debounce to true to let the script know it’s already active, after which it’s completely we set it to false again:

db = true
...
task.wait(1)
db =  false

Combined it’d look like

if db then return end
db = true
...
task.wait(1)
db = false

So for your code it’d be:

local TweenService = game:GetService("TweenService")
local button = script.Parent

local tweenInfo = TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
local originalSize = button.Size
local originalRotation = button.Rotation
local db = false

button.MouseEnter:Connect(function()
	if db then return end
	db = true

	local sizeTween = TweenService:Create(button, tweenInfo, {Size = originalSize + Vector3.new(0.1, 0.1, 0)})
	sizeTween:Play()
	local rotationTween = TweenService:Create(button, tweenInfo, {Rotation = originalRotation + Vector3.new(0, 0, 6)})
	rotationTween:Play()

	rotationTween.Completed:Wait() -- wait
	db = false
end)

button.MouseLeave:Connect(function()
	if db then return end
	db = true

	local sizeTween2 = TweenService:Create(button, tweenInfo, {Size = originalSize})
	sizeTween2:Play()
	local rotationTween2 = TweenService:Create(button, tweenInfo, {Rotation = originalRotation})
	rotationTween2:Play()

	rotationTween.Completed:Wait() -- wait
	db = false
end)

Didn’t work, the guibutton still isnt moving.

Actually scrap that, revert the changes, the real problem is that you are adding a Vector3 to a number and UDim2 value, this is what you did wrong:

-- Size is a UDim2 value
originalSize + Vector3.new(0.1, 0.1, 0)
-- Rotation is a number value
originalRotation + Vector3.new(0, 0, 6)

To fix this do the following:

originalSize + UDim2.fromScale(.1, .1) 
-- you can use UDim2.new(scaleX, offsetX, scaleY, offsetY) as well

and for the rotation it has to be a number not a Vector3:

originalRotation + 15

Plus you can combine both tweens because it’s for the same instance,

so instead of needing to call 2 tweens use:

local tween = TweenService:Create(button, tweenInfo, {
	["Size"] = originalSize + UDim2.fromScale(.1, .1), 
	["Rotation"] = originalRotation + 15
})

The tween format is incorrect.

Your code:

local tweenInfo = TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)

What it should be:

local tweenInfo = TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.Out, 0)

(I don’t know if this will fix the entire issue, but it would fix one)

image
LOL it worked too well, but i can mess around with the setting to fix it, thanks!

1 Like

That would not change anything as the last parameter you put in is set to 0 by default:

:skull: Tweens should not be this complicated

1 Like

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