Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Tweening the transparency of a model?

Asked by 5 years ago
Edited 5 years ago

Hi, im trying to tween the transparency of a model. This is the script im trying out

local ts = game:GetService("TweenService")
local info = TweenInfo.new(4)

local function tweenModel(model)
    local tr = Instance.new("IntValue")
    tr.Value = 0
    local parts = model:GetChildren()

    tr:GetPropertyChangedSignal("Value"):Connect(function()
        for i,v in pairs(parts) do
            if v.ClassName == "Part" or v.ClassName == "UnionOperation" then
                v.Transparency = tr.Value
            end
        end
    end)

    local tween = ts:Create(tr, info, {Value = 1})
    tween:Play()

    tween.Completed:connect(function()
        tr:Destroy()
        model:Destroy()
    end)
end

But the model just dissapears in under a second. Is there a way to make it disappear slow? I think it doesnt even set the transparency up but just destroy the model in the end.

1 answer

Log in to vote
0
Answered by 5 years ago

Didn't test. Should work.

local function tweenModel(model)

    local TimesToChange = 10
    local AmountOfTransparancyToChange = 0.1
    local AddOrDecrease = false -- False = Negate Transparency. True = Add Transparency
    local parts = model:GetChildren()

        for i,v in pairs(parts) do

            if v.ClassName == "Part" or v.ClassName == "UnionOperation" then

                if AddOrDecrease == false then

                for i = 0, TimesToChange do
                    v.Transparency = v.Transparency - AmountOfTransparancyToChange
                end

                else

                for i = 0, TimesToChange do
                    v.Transparency = v.Transparency + AmountOfTransparancyToChange
                end
            end
        end
    end
end
0
This kinda worksbut it removes part after part not everything at the same time. Jabba171 16 — 5y
Ad

Answer this question