Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Tweening the transparency of a model?

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

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

1 comment

0

This kinda worksbut it removes part after part not everything at the same time.

This discussion is preserved as it was. New answers, comments, and votes are closed.