How would I go about tweening different properties for multiple UI objects?

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 :sob:.

for some UI objects i need to tween more than 1 property. i appreciate any help thanks guys!!!

just use a loop and create tweens per Instance.

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.

1 Like

I assume you will be tweening the objects based on some sort of state changes.

If that’s the case you will need one attribute per each property at each state.

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.

test

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)
3 Likes

perfect job mate, thanks a million for your help! you explained everything thoroughly & simply for me to understand. :slight_smile:

1 Like

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