i thought about using a Tweenable tag for each gui object i’m tweening with an attribute called TweenProperties but i’m not sure whether this is the most efficient way. i don’t really know what to do next .
for some UI objects i need to tween more than 1 property. i appreciate any help thanks guys!!!
You can just make an arrays becouse as i see you are structuring it to be used like an array anyway.
You can also can cache tweens for further optimization.
Similarly, you’ll need more attributes for TweenInfo parameters if you wish to configure them too.
Store the props in TweenProperties attribute, seperate them by space or comma.
Add two more attributes: “States” to store the states, just like TweenProperties. And “CurrentState”, to trigger the transitions.
This approach is basic but it should give you the idea.
Script:
local TweenService = game:GetService("TweenService")
local CollectionService = game:GetService("CollectionService")
local function onTweenableAdded(tweenable)
local props = tweenable:GetAttribute("TweenProperties"):split(" ")
local states = tweenable:GetAttribute("States"):split(" ")
local tweens = {}
for i = 1, #states do
local state = states[i]
local propTable = {}
for j = 1, #props do
local prop = props[j]
propTable[prop] = tweenable:GetAttribute(state .. "_" .. prop)
end
tweens[state] = TweenService:Create(tweenable, TweenInfo.new(.5), propTable)
end
tweenable:GetAttributeChangedSignal("CurrentState"):Connect(function()
local currentState = tweenable:GetAttribute("CurrentState")
if tweens[currentState] then
tweens[currentState]:Play()
end
end)
end
for _, v in pairs(CollectionService:GetTagged("Tweenable")) do
onTweenableAdded(v)
end
CollectionService:GetInstanceAddedSignal("Tweenable"):Connect(onTweenableAdded)