Skip to content

Sounds, lights and effects ​

Sounds ​

A Sound inside a part is heard around that part; inside a Tool, around whoever holds it; anywhere else, everywhere.

lua
local sound = new("Sound", world.Coin)
sound.soundId = "coin"   -- a built-in sound, or "asset:123" for one you uploaded
sound.volume = 0.8
sound:play()
Member
soundId"coin", "click", "swing", "hit", "win", "music", or "asset:123"
volume0 to 1
loopedPlays round and round
playingWhether it is playing
play(), stop()
  • A Script's sound plays for every player (a looped one also for players who join later). A ClientScript's plays for that player only.
  • In KHIM Engine, a Sound's Play at start plays it for everyone when the game starts - background music with Looped.
  • Upload your own .wav sounds in the Assets panel (Models, pictures and sounds).

Lights ​

A Light inside a part makes the part give off light: a lamp, a torch, a neon sign that really lights the wall, a headlamp.

lua
local lamp = new("Light", world.Lamp)
lamp.color = rgb(255, 200, 140)
lamp.brightness = 2      -- 0 to 10
lamp.range = 20          -- units, up to 60
lamp.angle = 360         -- all round; less is a cone (a spotlight)
lamp.direction = vec3(0, -1, 0)  -- a cone's direction, in the part's own directions
lamp.innerAngle = 30     -- a cone's full-strength middle

Lights show best at night or indoors. Up to 16 lights are drawn at once at the top graphics levels (fewer on weaker devices) - the ones nearest the camera. Lights don't cast shadows.

The time of day: lighting ​

lua
lighting.clockTime = 18.5                    -- 6:30 pm
lighting:tween({clockTime = 20}, 60)          -- dusk over a minute
lighting.brightness = 2
lighting.fogColor = rgb(200, 210, 230)
lighting.fogStart, lighting.fogEnd = 50, 400
lighting.globalShadows = true
print(lighting.timeOfDay)                     -- "18:30:00"
Member
clockTimeHours, 0 to 24 (or timeOfDay as "hh:mm:ss")
brightnessThe sun's strength
ambient, outdoorAmbientLight that comes from everywhere, indoors and outdoors
fogColor, fogStart, fogEndFog, in units from the camera
globalShadowsShadows on or off
exposureCompensationBrighter or darker overall
geographicLatitudeHow high the sun goes
getSunDirection()Where the sun is

The sky, sun, moon, stars and clouds follow clockTime by themselves. A Script's change reaches every player; a ClientScript's only its own player.

Particles ​

A ParticleEmitter (Particles in KHIM Engine's menus) throws off fire, smoke, sparks, magic, rain... Insert one on a part, then pick Start from in the Inspector for one of 17 ready-made effects - Fire, Smoke, Sparks, Sparkles, Magic aura, Embers, Shockwave, Explosion, Electric, Heal, Portal, Rune circle, Rain, Snow, Leaves, Dust, Bubbles - and change any number from there.

lua
local fx = new("ParticleEmitter", world.Sword.Blade)
fx.texture = "Sparkle"
fx.rate = 30                   -- a second
fx.lifetime = vec3(0.5, 1, 0)  -- between 0.5 and 1 second
fx.speed = vec3(2, 4, 0)
fx.color = rgb(140, 90, 255)
fx.lightEmission = 1           -- glows where they cross
fx.lockedToPart = true         -- they move with the part
fx:emit(20)                    -- a burst of 20 now

Some of what it can do: pictures and flipbooks, sizes, colours and transparency that change over each particle's life (NumberSequence, ColorSequence), shapes to throw from (box, sphere, cylinder, disc, cone), bursts on a schedule, drag, turbulence, collisions, trails, and sub-emitters. A ParticleForce on a part pulls, swirls or blows every particle near it. An Effect plays all the particles on its part and inside it as one: play(), stop(), clear().

Particles are drawn by each player's device: a ClientScript's emitter is that player's alone.

Pictures on parts: Decal and Texture ​

lua
local poster = new("Decal", world.Wall)
poster.image = "star"       -- or "asset:123"
poster.face = "Front"       -- "Front", "Back", "Left", "Right", "Top", "Bottom"

local tiles = new("Texture", world.Floor)
tiles.image = "asset:456"
tiles.face = "Top"
tiles.tileSize = vec2(4, 4)   -- repeats every 4 units

Highlight ​

Outlines its part (and everything inside it) and tints it - through walls unless depthMode = "Occluded":

lua
local glow = new("Highlight", world.Treasure)
glow.fillColor = rgb(255, 220, 0)
glow.fillTransparency = 0.6
glow.outlineColor = rgb(255, 255, 255)

Beam and Trail ​

lua
local laser = new("Beam", world.Turret)       -- a band from one part to another
laser.part1 = world.Target
laser.color = rgb(255, 40, 40)
laser.width0, laser.width1 = 0.3, 0.3

local trail = new("Trail", world.Ball)        -- the streak a moving part leaves
trail.lifetime = 0.5
trail.width0, trail.width1 = 1, 0

Who sees changes to effects ​

The Decals, Textures, Highlights, Beams, Trails, Lights and particles a world is saved with reach every player. After that each player's device keeps its own copy: a server Script's change to one does not reach players (except a ParticleEmitter's settings and emit). To switch a light or change a decal for players, do it from a ClientScript - the server can tell clients to with net.sendAll:

lua
-- Script
net.sendAll("lights", false)

-- ClientScript
net.on("lights", function(on)
    for _, lamp in tags.get("StreetLamp") do lamp.Light.enabled = on end
end)

Explosions and breaking things ​

See Building, destruction, achievements.