I’m making a hover script that smoothly tweens the ImageButton and rotates it slightly when it’s hovered on, I know how to change the size when the mouse enters and leaves but I have no clue on how to make it rotate, any help would be appreciated. (beginner scripter)
The script:
local startSize = UDim2.new(0.062, 0,0.108, 0)
local hoverSize = UDim2.new(0.055, 0,0.108, 0)
script.Parent.MouseEnter:Connect(function()
script.Parent:TweenSize(hoverSize,Enum.EasingDirection.Out,Enum.EasingStyle.Sine,.25,true)
end)
script.Parent.MouseLeave:Connect(function()
script.Parent:TweenSize(startSize,Enum.EasingDirection.Out,Enum.EasingStyle.Sine,.25,true)
end)
You can probably use Tweenservice to rotate a gui:
local gui = YourButton
local TweenService = game:GetService(“TweenService”)
local Info = TweenInfo.new(time, easingdirection, easingstyle)
gui.MouseEnter:Connect(function()
local NewTween = TweenService:Create(gui, Info, {Rotation = 90} — Rotates gui 90 degrees
NewTween:Play()
end)
— Tween it back using same method for mouseleave
If you wanted to smoothly rotate it, here is an updated version to do this (again, adjust it as needed):
local startSize = UDim2.new(0.062, 0, 0.108, 0)
local hoverSize = UDim2.new(0.055, 0, 0.108, 0)
local startRotation = 0
local hoverRotation = 10
local rotationSpeed = 2 -- Adjust the speed of rotation here
local function rotateGuiSmoothly(gui, startAngle, targetAngle, speed)
local direction = (targetAngle - startAngle) / math.abs(targetAngle - startAngle)
for angle = startAngle, targetAngle, speed * direction do
gui.Rotation = angle
wait() -- Waits a frame before the next rotation step
end
end
script.Parent.MouseEnter:Connect(function()
script.Parent:TweenSize(hoverSize, Enum.EasingDirection.Out, Enum.EasingStyle.Sine, .25, true)
rotateGuiSmoothly(script.Parent, startRotation, hoverRotation, rotationSpeed)
end)
script.Parent.MouseLeave:Connect(function()
script.Parent:TweenSize(startSize, Enum.EasingDirection.Out, Enum.EasingStyle.Sine, .25, true)
rotateGuiSmoothly(script.Parent, hoverRotation, startRotation, rotationSpeed)
end)