Using string to tween a property

I made a dictionary consisting of types of objects and the properties I want to tween of each.

local uiDefs = { 
    ["UIStroke"] = {"Transparency"},
    ["ImageLabel"] = {"ImageTransparency", "BackgroundTransparency"},
    ["TextLabel"] = {"TextTransparency", "BackgroundTransparency", "TextStrokeTransparency"}
}

I attempted to loop through the GuiObjects, check to make sure they are the correct class, and modify the properties. However, because the properties are strings within the table, it errors when attempting to use them as property names.

-- pre-defined vars "object" and "tweenInfo"
for name, defTable in pairs(uiDefs) do
    if object:IsA(name) then
        for _, prop in pairs(defTable) do
            game:GetService("TweenService"):Create(object, tweenInfo, {prop = 1})
        end
    end
end
-- error: TweenService:Create no property named 'prop' for object 'Frame'

How can I modify the prop variable to use it as a property name within propertyTable?

As far as I know, enclosing the variable in square bracket would do the trick.

1 Like

LMFAO, you’re right!! i don’t know why i didnt just try this. thank you!!!

Haha no worries! I never expected that would work as well!

Anyways, happy developing and have a good day.

1 Like

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