Better way to tween UI

Hello! I am making a UI tween asset, and I am figuring out if there’s a better way to do this

local TS = game:GetService("TweenService")
local info = TweenInfo.new(.25, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut) -- Changeable, number is how much sec it'll take to complete the animation

local Settings = {
	["Transparency"] = {true, 0.5}; -- makes gui transparent, change num for transparency, 0 being none, 1 being max
	["Rotation"] = {true, 15}; -- Rotates button, change num for rotation
	["Smaller"] = true;
	["Bigger"] = true;
	
}

local gui = script.Parent:GetDescendants()

for i, buttons in gui do
	if buttons:IsA("TextButton") or buttons:IsA("ImageButton") then
		buttons.MouseEnter:Connect(function()
			if Settings["Transparency"] then
				TS:Create(buttons, info, {Transparency = Settings["Transparency"][2]}):Play()
				
				
			end
			
			if Settings["Rotation"] then
				TS:Create(buttons, info, {Rotation = Settings["Rotation"][2]}):Play()
				
			end
		end)
		
		
		buttons.MouseLeave:Connect(function()
			if Settings["Transparency"] then
				TS:Create(buttons, info, {Transparency = 0}):Play()
			end
			
			if Settings["Rotation"] then
				TS:Create(buttons, info, {Rotation = 0}):Play()
				
			end
		end)
		
	end
	
end
3 Likes

local TS = game:GetService("TweenService")
local info = TweenInfo.new(.25, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut) 

local Settings = {
	Transparency = 0.5; --Simply set to false if not wanted.
	Rotation = 15; --same as above.
	Smaller = true;
	Bigger = true;
}

local toTweenOut = {}
local toTweenIn = {}
if Settings.Transparency then toTweenIn['Transparency'] = Settings.Transparency toTweenOut['Transparency'] = 0 end
if Settings.Rotation then toTweenIn['Rotation'] = Settings.Rotation toTweenOut['Rotation'] = 0 end

for _, button in script.Parent:GetDescendants() do 
	if not button:IsA('TextButton') and not button:IsA('ImageButton') then continue end
	button.MouseEnter:Connect(function()
		TS:Create(button, info, toTweenIn):Play()
	end)

	button.MouseLeave:Connect(function()
		TS:Create(button, info, toTweenOut):Play()
	end)
end
1 Like

That’s an interested way to do it…

2 Likes

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