Skip to content

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.

Part_Icles is in ReplicatedStorage. The plugin puts it there and keeps it current.

WhenWhat the plugin does
The plugin startsMakes Part_Icles in ReplicatedStorage if none is there. Replaces a Part_Icles already in ReplicatedStorage or in the Workspace.
The toolbar Toggle is switched onReplaces the Part_Icles in ReplicatedStorage.
The Emit Code panel is shownReplaces the Part_Icles in ReplicatedStorage.
≡ ▸ Tools ▸ Insert Module is pressedPuts 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.

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

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.

WhatAfter Deactivate
ParticlesEvery particle in flight is removed, and every idle particle kept for reuse.
Streams and loopsAll stop.
Animate emittersEach is put back to the look it was built with.
TexturesEvery texture held by Preload is released.
Camera ShakeThe offset on the camera is removed.
LinkServiceIt is stopped. Linked parts get their Anchored state back.
The module’s foldersThey 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.

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 ActivateWhat happens
AbsoluteEmit, EnableEmit, AbsoluteEmitAt, EnableEmitAtNothing is made, by an emitter or by a stock emitter.
Emit, Enable, EmitAnimateParticles 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.

  • The module.
  • The emitter, with its children: PartIcleProperties, RenderTemplate, the Link and EmitParent values, 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.

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.

FeatureIn a LocalScriptIn a server Script
Particles of a Part, Attachment, Model, Beam, Trail, Lightning, Rocks or Rope emitterMade on that machine. Only that player sees them.Made under the server’s camera. No player sees them.
Blur, Bloom and ColorCorrection emittersThe effect shows on that player’s screen only.Made under the server’s camera. No player sees the effect.
Atmosphere emittersMade 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 IntoThe label shows on that player’s screen.The label has nowhere to appear. It is never visible.
Camera ShakeWorks.Ignored. Output shows once: [Part-Icles] CameraShake ignored on the server (no camera).
DistortionWorks.Ignored. Output shows once: [Part-Icles] Distortion ignored on the server (no screen).
Preload Texture, Preload, DeloadWork.Do nothing.
Z-Offset, and Orientation FacingCamera or FacingCameraWorldUpWork.They act on the server’s camera, not on a player’s.
A Link to the cameraWorks.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 ofKept
A Part, Model, Beam, Trail, Lightning, Rocks or Rope emitterIn the folder that Part_Icles:GetFolder() gives.
An Attachment, Light or Sound emitterOn an invisible Part named _Carrier in that folder. The carrier stays with the emitter’s parent.
A Blur, Bloom or ColorCorrection emitterUnder the camera.
An Atmosphere emitterIn Lighting.
An ImageLabel emitterIn a ScreenGui named PartIclesScreenHost, in the player’s PlayerGui.
Any emitter with Emit Into setWhere 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.

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 gameCall
A stream or loop that is always onPart_Icles:AbsoluteEnable(effect). See Starting, stopping and waiting.
One play of an effectPart_Icles:AbsoluteEmit(effect). See Firing an effect.
Textures loaded for effects added laterPart_Icles:Preload(root). See Textures.