Hello guys. I want to make Tweening function. For it, I did such thing:
local TweenParams = {
["Size"] = UDim2.fromScale,
["Position"] = UDim2.fromScale,
["Transparency"] = function(x) return x end,
}
And, as you see here, there’s 2 types of functions: with 1 and 2 variables.
Also, I have another table, which contains data, like this:
local TweenCur = {"Position", 1, 0.5}
local TweenCur = {"Size", 0.25, 1}
local TweenCur = {"Transparency", 1}
And, I have 2 questions: what’s the best way to make this function calls, and, how I can get amount of arguments required for function to operate?
Bloxynet
(Bloxy)
#3
Maybe you want something like this?
local TweenService = game:GetService("TweenService")
local TweenParams = {
["Size"] = {
Property = "Size",
EasingStyle = Enum.EasingStyle.Linear,
EasingDirection = Enum.EasingDirection.InOut,
Time = 1,
},
["Position"] = {
Property = "Position",
EasingStyle = Enum.EasingStyle.Linear,
EasingDirection = Enum.EasingDirection.InOut,
Time = 1,
},
["Transparency"] = {
Property = "Transparency",
EasingStyle = Enum.EasingStyle.Linear,
EasingDirection = Enum.EasingDirection.InOut,
Time = 1,
},
}
local TweenCur1 = {"Position", UDim2.new(1, 0, 0.5, 0)}
local TweenCur2 = {"Size", UDim2.new(0.25, 0, 1, 0)}
local TweenCur3 = {"Transparency", 0.5}
local function createTween(object, tweenData)
local property = tweenData[1]
local targetValue = tweenData[2]
local tweenInfo = TweenParams[property]
if not tweenInfo then
return
end
local tweenGoal = {}
tweenGoal[property] = targetValue
local tween = TweenService:Create(object, TweenInfo.new(tweenInfo.Time, tweenInfo.EasingStyle, tweenInfo.EasingDirection), tweenGoal)
return tween
end
local Frame = script.Parent:WaitForChild("ScreenGui").Frame
local tween1 = createTween(Frame, TweenCur1)
local tween2 = createTween(Frame, TweenCur2)
local tween3 = createTween(Frame, TweenCur3)
tween1:Play()
tween2:Play()
tween3:Play()
1 Like