for _,Part in next(), monstr.Model:children() do
if Part:IsA('BasePart') then
local f = Instance.new("ParticleEmitter")
f.SpreadAngle = Vector2.new(100,100)
f.Lifetime = NumberRange.new(1,1)
f.Texture = "http://www.roblox.com/asset/?id=431361643"
f.Parent = Part
for i = 0,1, 0.1 do
wait()
Part.Transparency = i
print(i)
end
f:Destroy()
end
end
how i make it apply to all children at once and not for every next children?
for x,y in pairs(monstr.Model:GetChildren()) do
local f = Instance.new("ParticleEmitter")
f.SpreadAngle = Vector2.new(100,100)
f.Lifetime = NumberRange.new(1,1)
f.Texture = "http://www.roblox.com/asset/?id=431361643"
f.Parent = y
for i = 0,1, 0.1 do
wait()
y.Transparency = i
print(i)
end
f:Destroy()
end
Create a coroutine for each part so that the waits are run asynchronously:
for _, Part in pairs(monstr.Model:GetChildren()) do
if Part:IsA("BasePart") then
-- create f
f.Parent = Part
coroutine.wrap(function()
for i = 0, 1, 0.1 do
Part.Transparency = i
wait()
end
f:Destroy()
end
end
end
Run the for loops methodically so that they all use one wait:
for _, Part in pairs(monstr.Model:GetChildren()) do
if Part:IsA("BasePart") then
-- create f
f.Parent = Part
end
end
for i = 0, 1, 0.1 do
for _, Part in pairs(monstr.Model:GetChildren()) do
if Part:IsA("BasePart") then
Part.Transparency = i
end
end
wait()
end
for _, Part in pairs(monstr.Model:GetChildren()) do
if Part:IsA("BasePart") then
-- effect is obviously not called f
Part.f:Destroy()
end
end
It’s probably easier to clean up the array before continuing though:
local children = {}
for _, Part in pairs(monstr.Model:GetChildren()) do
if Part:IsA("BasePart") then
children[#children + 1] = Part
end
end
for _, Part in pairs(children) do
-- create f
f.Parent = Part
end
for i = 0, 1, 0.1 do
for _, Part in pairs(children) do
Part.Transparency = i
end
wait()
end
for _, Part in pairs(children) do
Part.f:Destroy()
end
The comments are signs of pseudocode, you can flesh it out so that it makes sense.
iirc I am pretty sure you can’t do this without spawn(function().
Scripts on roblox run on 1 thread, so this means it will do everything one at a time.
To accomplish this here is what you would do:
spawn(function()
for _,Part in next(), monstr.Model:children() do
if Part:IsA('BasePart') then
local f = Instance.new("ParticleEmitter")
f.SpreadAngle = Vector2.new(100,100)
f.Lifetime = NumberRange.new(1,1)
f.Texture = "http://www.roblox.com/asset/?id=431361643"
f.Parent = Part
for i = 0,1, 0.1 do
wait()
Part.Transparency = i
print(i)
end
f:Destroy()
end
end
end)