How can I send a property to be tweened within a function?

I’m sure the title is self explanatory. Here’s an example of what I’m talking about:

function Tween(GUI,Property)
    game:GetService("TweenService"):Create(GUI,TweenInfo.new(1,"Linear","InOut"),{Property = 0})
end

Tween(script.Parent,"BackgroundTransparency") 

As you can see, I’m wanting the BackgroundTransparency of script.Parent to be tweened. How can I accomplish this by sending the GUI object with it’s property to a function where there it will be tweened? Thanks in advance.

May I ask, what is the object of script.Parent?

function Tween(GUI, Property: string, value: any)
    local tween = game:GetService("TweenService"):Create(
       GUI,
       TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut),
    {[Property] = value}) -- wrap the index in brackets and set it's value to something passed in the function

    tween:Play() -- play the tween
end

Tween(script.Parent, "BackgroundTransparency", 0) 
1 Like

Thanks, I’ve been looking for hours.