Getting the module into a script
An effect is played in the game by a ModuleScript named Part_Icles. A script loads the module, starts it once, then fires effects. This page covers loading and starting. Exercise 17 does the same by hand.
Where the module is
Section titled “Where the module is”Part_Icles is in ReplicatedStorage. The plugin puts it there and keeps it current.
| When | What the plugin does |
|---|---|
| The plugin starts | Makes Part_Icles in ReplicatedStorage if none is there. Replaces a Part_Icles already in ReplicatedStorage or in the Workspace. |
| The toolbar Toggle is switched on | Replaces the Part_Icles in ReplicatedStorage. |
| The Emit Code panel is shown | Replaces the Part_Icles in ReplicatedStorage. |
| ≡ ▸ Tools ▸ Insert Module is pressed | Puts a Part_Icles in the Workspace and selects it. One already there is replaced. This is one step in Studio’s undo history. |
Scan and Fix, Insert Module, Emit Code describes the two tools.
Loading the module
Section titled “Loading the module”local Part_Icles = require(game.ReplicatedStorage:WaitForChild("Part_Icles"))require gives back one table. A call on it is written with a colon: Part_Icles:AbsoluteEmit(item). One helper is written with a dot: Part_Icles.await(seconds).
Activate and Deactivate
Section titled “Activate and Deactivate”Part_Icles:Activate()Part_Icles:Activate() starts the module. It takes nothing and gives nothing back.
- It is needed once on each machine where a script fires effects. That is each player’s machine, and the server too if a server Script fires effects.
- Each machine runs the module separately, with its own particles.
- A second call while the module is running does nothing.
- On a player’s machine it also loads the textures of every emitter whose Preload Texture is on. Textures gives the detail.
- It starts no emitter. An emitter with Enabled on, or an Animate emitter with Loop on, stays idle until a script starts it.
- On a player’s machine the module updates in the render step, after camera and character scripts have run. A particle linked to the camera or to a character reads the pose of the same frame. On a server it updates on Heartbeat.
Part_Icles:Deactivate() stops the module and removes everything it made.
| What | After Deactivate |
|---|---|
| Particles | Every particle in flight is removed, and every idle particle kept for reuse. |
| Streams and loops | All stop. |
| Animate emitters | Each is put back to the look it was built with. |
| Textures | Every texture held by Preload is released. |
| Camera Shake | The offset on the camera is removed. |
LinkService | It is stopped. Linked parts get their Anchored state back. |
| The module’s folders | They are deleted. |
Deactivate may be called twice without harm. After it the module is as it was before the first Activate. See A call made before Activate.
A call made before Activate
Section titled “A call made before Activate”The Output window shows this line once, until the next Activate. <Method> is the name of the call.
[Part-Icles] :<Method>() called before :Activate() - particles will not update until the engine is activated. Call Particle:Activate() once at startup.Call made before Activate | What happens |
|---|---|
AbsoluteEmit, EnableEmit, AbsoluteEmitAt, EnableEmitAt | Nothing is made, by an emitter or by a stock emitter. |
Emit, Enable, EmitAnimate | Particles are made, and they never move and never end. They pile up to the Particle Cap. |
Put Part_Icles:Activate() straight after the require line.
What must exist where the script runs
Section titled “What must exist where the script runs”- The module.
- The emitter, with its children:
PartIcleProperties,RenderTemplate, theLinkandEmitParentvalues, and its flipbook folders. - The emitter’s attributes.
- A parent for the emitter. An emitter that is destroyed, or that has no parent, is ignored.
A LocalScript runs on the player’s machine. The emitter must be in a place that reaches that machine, such as the Workspace or ReplicatedStorage. ServerStorage does not reach it.
LocalScript or server Script
Section titled “LocalScript or server Script”A LocalScript runs on one player’s machine. Particles fired there are made on that machine, and only that player sees them.
A server Script runs on the server. The module keeps its particles under the camera, and the server has a camera of its own that no player sees. Particles fired from a server Script are made there. No player sees them.
| Feature | In a LocalScript | In a server Script |
|---|---|---|
| Particles of a Part, Attachment, Model, Beam, Trail, Lightning, Rocks or Rope emitter | Made on that machine. Only that player sees them. | Made under the server’s camera. No player sees them. |
| Blur, Bloom and ColorCorrection emitters | The effect shows on that player’s screen only. | Made under the server’s camera. No player sees the effect. |
| Atmosphere emitters | Made in Lighting on that player’s machine. Only that player sees it. | Made in Lighting on the server, for every player. |
| ImageLabel emitters with no Emit Into | The label shows on that player’s screen. | The label has nowhere to appear. It is never visible. |
| Camera Shake | Works. | Ignored. Output shows once: [Part-Icles] CameraShake ignored on the server (no camera). |
| Distortion | Works. | Ignored. Output shows once: [Part-Icles] Distortion ignored on the server (no screen). |
Preload Texture, Preload, Deload | Work. | Do nothing. |
Z-Offset, and Orientation FacingCamera or FacingCameraWorldUp | Work. | They act on the server’s camera, not on a player’s. |
| A Link to the camera | Works. | The emitter follows the server’s camera, not a player’s. |
Where each kind of particle is kept, on the machine that fired it:
| Particle of | Kept |
|---|---|
| A Part, Model, Beam, Trail, Lightning, Rocks or Rope emitter | In the folder that Part_Icles:GetFolder() gives. |
| An Attachment, Light or Sound emitter | On an invisible Part named _Carrier in that folder. The carrier stays with the emitter’s parent. |
| A Blur, Bloom or ColorCorrection emitter | Under the camera. |
| An Atmosphere emitter | In Lighting. |
| An ImageLabel emitter | In a ScreenGui named PartIclesScreenHost, in the player’s PlayerGui. |
| Any emitter with Emit Into set | Where Emit Into points. |
Effects must be fired from a LocalScript. Do not fire them from a server Script. To show one effect to every player, the server calls FireAllClients on a RemoteEvent. Each player’s LocalScript fires the effect when the event arrives. Show one effect to every player gives both scripts.
Four things follow from firing on each player’s machine.
- Each machine needs its own
Part_Icles:Activate(), and the emitter must be in a place that reaches it. - Each player sees the same effect, not the same particles. Spread, ranges and random offsets are rolled on each machine.
- Events and their scripts run on each machine. An On Hit script runs once for each player who sees the effect. Do not use it to decide damage or score. Let the server make its own test.
- The Particle Cap is counted on each machine separately.
Nothing starts by itself in a game
Section titled “Nothing starts by itself in a game”The plugin does not run while the game runs. That holds for Play and Run in Studio and for a live server.
In the editor the plugin does three things for you. It starts every emitter whose Enabled is on. It resumes every Animate emitter whose Loop is on. It loads textures when Preload Texture is switched on.
In a game the module does none of this until a script asks. An emitter that stays idle gives the reason.
| To get in the game | Call |
|---|---|
| A stream or loop that is always on | Part_Icles:AbsoluteEnable(effect). See Starting, stopping and waiting. |
| One play of an effect | Part_Icles:AbsoluteEmit(effect). See Firing an effect. |
| Textures loaded for effects added later | Part_Icles:Preload(root). See Textures. |