Here is an open source Tweening Module that handles Tweening of Objects
I wrote it in like an hour as I decided to finally streamline the tweening of objects in code.
--mo.TweenTextSize(Obj, speed, style, size)
--mo.TweenAnchorPoint(Obj, speed, style, anchorPoint)
--mo.TweenTransparency(Obj,speed,style,trans)
--mo.TweenPositionTransparency(Obj,speed,style,trans,position)
--mo.TweenColor(Obj, speed,style, color)
--mo.TweenRotation(Obj, speed,style, rotation)
--mo.TweenScrollbarPosition(Obj, speed, style, position)
--mo.TweenTextStrokeTransparency(Obj, speed, style, transparency)
--mo.TweenSize(Obj, speed,style, size)
--mo.TweenPosition(Obj,speed,style,position)tweenhandle(Obj,tweenInfo,goal)
--example of using it in a script
--moduleppath= this script whereever it is
--mo=require(modulepath)
--function TweenDescendants(Obj,speed,style,trans,position)
-- for i,objects in ipairs(Obj:GetDescendants()) do
-- if Obj[i]:IsA("TextLabel") or Obj[i]:IsA("TextButton") or Obj[i]:IsA("TextBox") or Obj[i]:IsA("ImageLabel") or Obj[i]:IsA("ImageButton") then
-- if trans~=nil and position ~=nil then
-- mo.TweenPositionTransparency(Obj[i],speed,style,trans,position)
-- elseif position==nil and trans~=nil then
-- mo.TweenTransparency(Obj[i],speed,style,trans)
-- elseif position~=nil and trans==nil then
-- mo.TweenPosition(Obj[i],speed,style,trans)
-- end
-- end
-- end
--end
local mo = {}
TweServ=game:GetService("TweenService")
local function tweenhandle(Obj, tweenInfo, goal)
local tweenThread
tweenThread = spawn(function()
local tween = TweServ:Create(Obj, tweenInfo, goal)
tween:Play()
tween.Completed:Wait()
tween:Cancel()
tweenThread:Disconnect()
end)
end
function mo.TweenPosition(Obj,speed,style,position)
local goal={}
goal.Position=position
local tweenInfo = TweenInfo.new(speed,style)
tweenhandle(Obj,tweenInfo,goal)
end
function mo.TweenSize(Obj, speed,style, size)
local goal = {}
goal.Size = size
local tweenInfo = TweenInfo.new(speed,style)
tweenhandle(Obj,tweenInfo,goal)
end
function mo.TweenTextStrokeTransparency(Obj, speed, style, transparency)
local goal = {}
goal.TextStrokeTransparency = transparency
local tweenInfo = TweenInfo.new(speed, style)
tweenhandle(Obj,tweenInfo,goal)
end
function mo.TweenScrollbarPosition(Obj, speed, style, position)
local goal = {}
goal.ScrollBarPosition = position
local tweenInfo = TweenInfo.new(speed, style)
tweenhandle(Obj,tweenInfo,goal)
end
function mo.TweenRotation(Obj, speed,style, rotation)
local goal = {}
goal.Rotation = rotation
local tweenInfo = TweenInfo.new(speed,style)
tweenhandle(Obj,tweenInfo,goal)
end
function mo.TweenColor(Obj, speed,style, color)
local goal = {}
if Obj.ClassName=="TextLabel" or Obj.ClassName=="TextBox" or Obj.ClassName=="TextButton" then
if Obj.Text~="" then
goal.TextColor3=color
end
elseif Obj.ClassName=="ImageLabel" and Obj.ClassName=="ImageButton" then
goal.ImageColor3=color
end
goal.BackgroundColor3=color
local tweenInfo = TweenInfo.new(speed,style)
tweenhandle(Obj,tweenInfo,goal)
end
function mo.TweenPositionTransparency(Obj,speed,style,trans,position)
local goal={}
if Obj.ClassName=="TextLabel" or Obj.ClassName=="TextBox" or Obj.ClassName=="TextButton" then
if Obj.Text~="" then
goal.TextTransparency=trans
goal.TextStrokeTransparency=trans
end
elseif Obj.ClassName=="ImageLabel" and Obj.ClassName=="ImageButton" then
goal.ImageTransparency=trans
end
goal.Position=position
local tweenInfo = TweenInfo.new(speed,style)
tweenhandle(Obj,tweenInfo,goal)
end
function mo.TweenTransparency(Obj,speed,style,trans)
local goal={}
if Obj.ClassName=="TextLabel" or Obj.ClassName=="TextBox" or Obj.ClassName=="TextButton" then
if Obj.Text~="" then
goal.TextTransparency=trans
goal.TextStrokeTransparency=trans
end
elseif Obj.ClassName=="ImageLabel" and Obj.ClassName=="ImageButton" then
goal.ImageTransparency=trans
end
local tweenInfo = TweenInfo.new(speed,style)
tweenhandle(Obj,tweenInfo,goal)
end
function mo.TweenAnchorPoint(Obj, speed, style, anchorPoint)
local goal = {}
goal.AnchorPoint = anchorPoint
local tweenInfo = TweenInfo.new(speed, style)
tweenhandle(Obj,tweenInfo,goal)
end
function mo.TweenTextSize(Obj, speed, style, size)
local goal = {}
goal.TextSize = size
local tweenInfo = TweenInfo.new(speed, style)
tweenhandle(Obj,tweenInfo,goal)
end
function mo.TweenBackgroundTransparency(Obj, speed, style, transparency)
local goal = {}
goal.BackgroundTransparency = transparency
local tweenInfo = TweenInfo.new(speed, style)
tweenhandle(Obj,tweenInfo,goal)
end
function mo.TweenBorderSizePixel(Obj, speed, style, size)
local goal = {}
goal.BorderSizePixel = size
local tweenInfo = TweenInfo.new(speed, style)
tweenhandle(Obj,tweenInfo,goal)
end
return mo