Can i use a variable to refer to a property on a tween?

Hello all! i have this script i’m making where i want to avoid having a ton of tweens all over the place, so i’m going to try to use a function to handle all of my tweens, but i want to know if it’ll work before i try anything, since i’m not actually using the function right now.

Here is my function

local function doTween(part,sec,prop,val)
	local tweenService = game:GetService("TweenService")
	local tweenInfo = TweenInfo.new(
		sec,
		Enum.EasingStyle.Linear,
		Enum.EasingDirection.Out,
		0,
		false,
		0
	)
	local tween = tweenService:Create(part, tweenInfo, {prop = val})
	tween:Play()
end

so does anyone know if that will work? “prop” is what’s used to refer to the property it’ll be tweening, but i dont know if this is a viable way to do properties

many thanks!

1 Like

From taking a quick look, I think it should work. How about you try it and then I am happy to help if you have any issues with the code.

Use

{
    [prop] = value
}

I assume you mean that prop is a string, the name of the property.

1 Like

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