Hello guys,
Once again I find myself in need for advise from more experienced devs.
Long story short, I got a few ParticleEmitters that need to instantiated or dumped into the workspace in different times, it’s a cosmetic need (I don’t want these Emitters to be firing at the very same time).
So I wrote a tiny module, code below:
local RandomizedSpawn = {}
function RandomizedSpawn.Spawn (entity, minTime, maxTime, coordinates, wrapper)
local clonedEntity = entity:Clone()
local waitInterval = math.random(minTime, maxTime)
wait(waitInterval)
clonedEntity.Position = coordinates
clonedEntity.Parent = wrapper
end
return RandomizedSpawn
And then from my script, I call like that:
randomizedSpawn.Spawn(DarkLeaf01, .5, 2, Vector3.new(-30.27, 17.604, -45.42), game.Workspace.Runtime.Emitters)
randomizedSpawn.Spawn(DarkLeaf02, .5, 2, Vector3.new(-20.52, 17.604, -53.05), game.Workspace.Runtime.Emitters)
randomizedSpawn.Spawn(DarkLeaf03, .5, 2, Vector3.new(-21.43, 17.604, -68.42), game.Workspace.Runtime.Emitters)
randomizedSpawn.Spawn(DarkLeaf04, .5, 2, Vector3.new(-38.1, 17.604, -93.36), game.Workspace.Runtime.Emitters)
randomizedSpawn.Spawn(LightLeaf01, .5, 2, Vector3.new(-26.71, 17.604, -37.18), game.Workspace.Runtime.Emitters)
randomizedSpawn.Spawn(LightLeaf02, .5, 2, Vector3.new(-16.9, 17.604, -51.13), game.Workspace.Runtime.Emitters)
randomizedSpawn.Spawn(LightLeaf03, .5, 2, Vector3.new(-33.97, 17.604, -57.93), game.Workspace.Runtime.Emitters)
randomizedSpawn.Spawn(LightLeaf04, .5, 2, Vector3.new(-33.97, 17.604, -74.32), game.Workspace.Runtime.Emitters)
My expectation was that the Spawn functions would be executed at once, and then wait for whatever is the delay and clone the Emitter to the workspace, but what is happening is that one call is waiting for the previous call to run… therefore the code block above can take up to 16 seconds to run… where what I wanted / was expecting was for the code block above to take maximum of 2 seconds to run.
Hopefully it make sense.
So the question is, how can I get the desired effect?
Thanks in advance.
EDIT: I’m currently storing these Emitters in the replicated storage.