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
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()
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.
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()