Is there anyway to Tween Transparency of a model?

So far I’ve heard it’s not possible to have a smoother effect on the model other than using the loop function itself. If additional, would size work as well?

		local Tween = game:GetService("TweenService")
		local Info = TweenInfo.new(1)
		for n, m in pairs (mon:GetChildren()) do
			local tween = Tween:Create(m,Info,{Transparency = 0})
			tween:Play()
			tween.Completed:Wait()
		end

mon is an humanoid model, R6 rig.

1 Like

A little bit of rearranging and setting the variable outside the scope, waiting for the final tween to complete only. Although some others might consider using task.spawn() or coroutines.

local Tween = game:GetService("TweenService")
local Info = TweenInfo.new(1)

local tween
for _, instance in pairs(mon:GetChildren()) do
	tween = Tween:Create(instance, Info, {Transparency = 0})
	tween:Play()
end
tween.Completed:Wait()
1 Like

Ty for responding. Since this is a rig R6, it detected humanoids and I’ve had the same problem as before. Following errors:

TweenService:Create no property named ‘Transparency’ for object ‘Humanoid’

on the lines

tween = Tween:Create(instance, Info, {Transparency = 0})

Unless there is a way to detect every other but humanoid.
For the other two you have suggested, mind giving me an example of transparency (and if possible, size) and how to use them?

Never mind, I solved my own problem using :GetDescendants() (which I’ve always thought was depreciated) and isA(""). Though, I’m still curious about task.spawn() and coroutines.

1 Like

Simply use if statements.

local Tween = game:GetService("TweenService")
local Info = TweenInfo.new(1)

local tween
for _, instance in pairs(mon:GetChildren()) do
	if type(instance.Transparency) == "number" then
		tween = Tween:Create(instance, Info, {Transparency = 0})
		tween:Play()
	end
end
tween.Completed:Wait()

Examples that use task.spawn() or coroutine.wrap() would be these:

task.spawn()

local Tween = game:GetService("TweenService")
local Info = TweenInfo.new(1)

for _, instance in pairs(mon:GetChildren()) do
	-- Disadvantageous on figuring out when it all is completed.
	-- Requires a boolean change(but will only know the first Tween is completed
	-- Might use a number to see if 1:1 is completed
	task.spawn(function()
		if type(instance.Transparency) == "number" then
			local tween = Tween:Create(instance, Info, {Transparency = 0})
			tween:Play()
			tween.Completed:Wait()
		end
	end)
end

coroutine.wrap()() – 2 versions

local Tween = game:GetService("TweenService")
local Info = TweenInfo.new(1)

-- A
for _, instance in pairs(mon:GetChildren()) do
	-- Unlike task.spawn(), using return within the function will return the value, not thread
	-- Still disavantageous because it cannot tell when it is done
	coroutine.wrap(function()
		if type(instance.Transparency) == "number" then
			local tween = Tween:Create(instance, Info, {Transparency = 0})
			tween:Play()
			tween.Completed:Wait()
		end
	end)()
end

-- B
local completed
for _, instance in pairs(mon:GetChildren()) do
	-- Different approach but returns the event, solves A problems
	completed = coroutine.wrap(function()
		if type(instance.Transparency) == "number" then
			local tween = Tween:Create(instance, Info, {Transparency = 0})
			tween:Play()
			return tween.Completed
		end
	end)()
end

completed:Wait()
1 Like

Wow! Thanks again for your time. I’ll look into more into those two, seems interesting to know more about.

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