Skip to content

Worked scripts

Each script on this page is a complete LocalScript, unless the example says otherwise. Put it in StarterPlayer ▸ StarterPlayerScripts, as in Exercise 17. Change the names to those of your own effects.

Every script loads the module, starts it, then makes its call. Each uses WaitForChild to find its effect, because a LocalScript can start before the workspace has arrived.

Under each script is what must be true of the emitter. “Built” means set in the plugin, in the editor.

local UserInputService = game:GetService("UserInputService")
local Part_Icles = require(game.ReplicatedStorage:WaitForChild("Part_Icles"))
Part_Icles:Activate()
local explosion = workspace:WaitForChild("Explosion")
UserInputService.InputBegan:Connect(function(input, gameProcessed)
if gameProcessed then
return
end
if input.KeyCode == Enum.KeyCode.E then
Part_Icles:AbsoluteEmit(explosion)
end
end)

Explosion is one emitter, or a Folder or Model of emitters. Every emitter in it must be built with an Emit count of 1 or more, or a Duration above 0. An emitter with both at 0 fires nothing.

local Players = game:GetService("Players")
local Part_Icles = require(game.ReplicatedStorage:WaitForChild("Part_Icles"))
Part_Icles:Activate()
local impact = workspace:WaitForChild("Impact")
local mouse = Players.LocalPlayer:GetMouse()
mouse.Button1Down:Connect(function()
Part_Icles:AbsoluteEmitAt(impact, mouse.Hit.Position)
end)

Impact is one emitter, or a Model that holds several. A Folder is rejected. The emitters must be made from a Part, an Attachment or a Model, and be in Emit mode. Impact is not moved, and nothing has to be cleaned up afterwards.

A position keeps each emitter’s own rotation. Pass mouse.Hit, which is a CFrame, to turn the effect as well.

local Part_Icles = require(game.ReplicatedStorage:WaitForChild("Part_Icles"))
Part_Icles:Activate()
local charge = workspace:WaitForChild("Charge")
local blast = workspace:WaitForChild("Blast")
local seconds = Part_Icles:AbsoluteEmit(charge)
if seconds then
task.wait(seconds)
end
Part_Icles:AbsoluteEmit(blast)

Charge must come to an end. If it holds an Animate emitter with Loop on and no Duration, the call gives back nil. Blast then fires at once.

Stream from a character’s hand, then stop that play

Section titled “Stream from a character’s hand, then stop that play”
local Players = game:GetService("Players")
local Part_Icles = require(game.ReplicatedStorage:WaitForChild("Part_Icles"))
Part_Icles:Activate()
local sparks = workspace:WaitForChild("Sparks")
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local hand = character:WaitForChild("RightHand")
local handle = Part_Icles:AbsoluteEmitAt(sparks, hand, {
Link = hand,
LinkMode = "Weld",
Duration = 5,
})
task.wait(2)
handle:SoftDisable()
handle:Wait()
print("The sparks have finished")

Sparks is an emitter made from a Part, an Attachment or a Model. It is in Emit mode, with a Rate above 0. The character must have a part named RightHand. The hand as origin makes particles start at the hand. Link keeps particles in flight with the hand.

handle:SoftDisable() lets the sparks in flight finish. handle:Disable() removes them at once. Other plays of Sparks are not touched.

local Players = game:GetService("Players")
local Part_Icles = require(game.ReplicatedStorage:WaitForChild("Part_Icles"))
Part_Icles:Activate()
local aura = workspace:WaitForChild("Aura")
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local hand = character:WaitForChild("RightHand")
Part_Icles:SetLink(aura, hand, "Weld")
Part_Icles:AbsoluteEnable(aura)
task.wait(10)
Part_Icles:AbsoluteDisable(aura)

Aura is one emitter with a Rate above 0. Its Emit count, Delay and Duration are not used. SetLink changes the emitter itself, so one emitter serves one hand. Use a separate emitter for each character.

local Part_Icles = require(game.ReplicatedStorage:WaitForChild("Part_Icles"))
Part_Icles:Activate()
local glow = workspace:WaitForChild("Glow")
Part_Icles:Enable(glow)
task.wait(8)
Part_Icles:SoftDisable(glow)

Glow is one emitter built with Mode set to Animate. SoftDisable lets the cycle in progress play to its end. Part_Icles:Disable(glow) resets the emitter at once. For a Folder of Animate emitters, use AbsoluteEnable and AbsoluteDisable.

To play exactly one cycle, build the emitter with Loop off and call Part_Icles:AbsoluteEmit(glow).

Fire a larger burst than the emitter was built with

Section titled “Fire a larger burst than the emitter was built with”
local UserInputService = game:GetService("UserInputService")
local Part_Icles = require(game.ReplicatedStorage:WaitForChild("Part_Icles"))
Part_Icles:Activate()
local sparks = workspace:WaitForChild("Sparks")
UserInputService.InputBegan:Connect(function(input, gameProcessed)
if gameProcessed then
return
end
if input.KeyCode == Enum.KeyCode.F then
Part_Icles:EnableEmitAt(sparks, sparks, { Count = 50 })
end
end)

Sparks is one emitter in Emit mode. EnableEmitAt rejects a container. The emitter is its own origin, so the burst stays where the emitter is. The count of 50 holds for this play only.

local Part_Icles = require(game.ReplicatedStorage:WaitForChild("Part_Icles"))
Part_Icles:Activate()
local explosion = workspace:WaitForChild("Explosion")
Part_Icles:AbsoluteEmit(explosion)
task.wait(0.2)
Part_Icles:AbsoluteSetTimescale(explosion, 0.25, 2)

The explosion runs at quarter speed for 2 seconds, then at its own speed again. The third value, the 2 seconds, must be given. Without it the call sets nothing. Emitters nested in a RenderTemplate are not slowed by this call.

Switch an ambient effect on when the game starts

Section titled “Switch an ambient effect on when the game starts”
local Part_Icles = require(game.ReplicatedStorage:WaitForChild("Part_Icles"))
Part_Icles:Activate()
local ambient = workspace:WaitForChild("Ambient")
Part_Icles:AbsoluteEnable(ambient)

Ambient is a Folder of emitters. Each emitter in Emit mode needs a Rate above 0. Nothing starts by itself in the game, even an emitter saved with Enabled on.

An effect fired in a LocalScript shows to that player only. To show it to everyone, the server tells every player’s LocalScript to fire it.

This example needs a RemoteEvent named PlayEffect in ReplicatedStorage. The first script is a Script in ServerScriptService.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local playEffect = ReplicatedStorage:WaitForChild("PlayEffect")
local function explodeAt(position)
playEffect:FireAllClients("Explosion", position)
end
task.wait(5)
explodeAt(Vector3.new(0, 10, 0))

The second is a LocalScript in StarterPlayer ▸ StarterPlayerScripts.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Part_Icles = require(ReplicatedStorage:WaitForChild("Part_Icles"))
Part_Icles:Activate()
local effects = ReplicatedStorage:WaitForChild("Effects")
local playEffect = ReplicatedStorage:WaitForChild("PlayEffect")
playEffect.OnClientEvent:Connect(function(effectName, position)
local effect = effects:FindFirstChild(effectName)
if effect then
Part_Icles:AbsoluteEmitAt(effect, position)
end
end)

Effects is a Folder in ReplicatedStorage. Explosion inside it is one emitter, or a Model that holds several. Call explodeAt wherever the game decides the explosion happens. The server sends only a name and a position. Each player’s machine makes its own particles.

local Part_Icles = require(game.ReplicatedStorage:WaitForChild("Part_Icles"))
Part_Icles:Activate()
local effects = game.ReplicatedStorage:WaitForChild("Effects")
Part_Icles:Preload(effects, true)

Effects is a Folder of emitters. The second value, true, covers every emitter in it, whatever its Preload Texture reads. Activate has already loaded the textures of emitters that were in the place with Preload Texture on.