How would I make a UI rotate from left to right

I’m trying to make a case system where a player can open it and it will rotate from left to right before revealing the item. I understand tween info and how to make it rotate 1 way but how would i make it rotate 20 degrees left then 20 degrees right?

Feel free to use this script I created for the exact same purpose. I had to modify it slightly from the original version, as the original script was meant to handle multiple buttons, but I do think it will still work. Let me know if I need to re-edit it :slight_smile:

Put this in a localscript with the button/image as the parent.

local runService = game:GetService('RunService')
local localPlayer = game.Players.LocalPlayer

local currentHovered = nil
local button = script.Parent

local spin = 0

local createHoverEvent = function()
	button.MouseEnter:Connect(function()
		currentHovered = button
		spin = 0
	end)
	button.MouseLeave:Connect(function()
		currentHovered = nil
		spin = 0
	end)
    button.MouseButton1Click:Connect(function()
       -- When the button is clicked
    end)
end

createHoverEvent()

runService.RenderStepped:Connect(function()
	if button == currentHovered then
		spin += .1
		if spin >= 360 then
			spin = 0
		end
		button.Rotation = math.sin(spin) * 10
	else
		button.Rotation *= .8
	end
end)
2 Likes