Second Life today in one place Gifts & freebies updated every hour 7 languages Free to list your store
12:49 SLT List your event+ List
Grid issue
  • Planned: Scheduled Billing Maintenance, Mon, Nov 16 09:30–10:30 SLT
  • Grid status: Unscheduled Group Chat Maintenance (investigating)
  • On now: Unitarian Universalist Saturday Service in UUtopia
  • On now: The Dharma of Community: Buddhist Society and the Householder
  • On now: SLCS Harvest Fest: Games, Music and Fun at Cheertopia
  • 14:00 SLT: NAD GOUGH Live at Moondance in Cascadia, 2:00 PM SLT
  • News: REZZ MALL: Second Life brands in one web mall
  • Viewer: Second Life Viewer 26.5 Adds Chat Modernization
  • Planned: Scheduled Billing Maintenance, Mon, Nov 16 09:30–10:30 SLT
  • Grid status: Unscheduled Group Chat Maintenance (investigating)
  • On now: Unitarian Universalist Saturday Service in UUtopia
  • On now: The Dharma of Community: Buddhist Society and the Householder
  • On now: SLCS Harvest Fest: Games, Music and Fun at Cheertopia
  • 14:00 SLT: NAD GOUGH Live at Moondance in Cascadia, 2:00 PM SLT
  • News: REZZ MALL: Second Life brands in one web mall
  • Viewer: Second Life Viewer 26.5 Adds Chat Modernization
LSL script

LSL sound loop script for ambient sound

Free LSL ambient sound script for Second Life: loop birds, waves, rain or a fire crackle from any object, set the volume and touch to turn it on and off.

52 lines ·

Sound brings a place to life: waves on a beach, birds in a garden, a crackling fireplace. This sound loop script plays a sound on repeat from any object, with a volume setting and touch to switch it on or off.

lsl-sound-loop-script.lsl · 52 lines Check this script
// Ambient Sound Loop - free LSL script from WhatSL (https://whatsl.com/scripts/lsl-sound-loop-script)
// Free to use, change and put in your own creations, also ones you sell.
//
// Plays a sound on repeat: birds, waves, a fire, rain, a shop jingle.
// Put a sound in the object's Contents (or paste a sound UUID into SOUND_NAME). Touch to turn it on and off.

string  SOUND_NAME   = "";    // "" = the first sound in Contents; or a sound name or UUID
float   SOUND_VOLUME = 0.6;   // 0.0 to 1.0; keep ambient sounds soft
integer START_ON     = TRUE;
integer OWNER_ONLY   = FALSE; // TRUE = only the owner can turn it on and off

integer gOn = FALSE;

string soundToPlay()
{
    if (SOUND_NAME != "") return SOUND_NAME;
    return llGetInventoryName(INVENTORY_SOUND, 0);
}

setSound(integer on)
{
    llStopSound();
    gOn = FALSE;
    if (!on) return;
    string snd = soundToPlay();
    if (snd == "")
    {
        llOwnerSay("Put a sound in my Contents, or set SOUND_NAME.");
        return;
    }
    llLoopSound(snd, SOUND_VOLUME);
    gOn = TRUE;
}

default
{
    state_entry()
    {
        setSound(START_ON);
    }

    touch_start(integer total)
    {
        if (OWNER_ONLY && llDetectedKey(0) != llGetOwner()) return;
        setSound(!gOn);
    }

    changed(integer change)
    {
        if (change & CHANGED_INVENTORY) setSound(gOn);
    }
}

Free to use, change and put in your own creations, also ones you sell.

How to set it up

  1. Put a sound into the object's Contents (or copy a sound's UUID).
  2. Add the script and save. The sound starts playing.
  3. Touch the object to stop it and touch again to start it.

Settings

  • SOUND_NAME: empty plays the first sound in the Contents. You can also type a sound name or paste a sound UUID.
  • SOUND_VOLUME: 0.0 to 1.0. Ambient sounds sound best soft, around 0.3 to 0.6.
  • START_ON: whether the sound plays as soon as the script starts.
  • OWNER_ONLY: TRUE stops visitors from switching it off.

Tips

  • Use sounds that are made to loop, without a gap or click at the end.
  • Visitors hear the sound near the object. Place several quiet sources around a big area rather than one loud one.
  • For music for a whole parcel, use the parcel's music stream instead of a sound loop.

Frequently asked questions

Why can't I hear anything?

Check that sound effects are turned up in your viewer's volume controls, that the object has a sound in its Contents, and that you are close enough to the object.

Can I play several sounds in a row?

This script loops one sound. Playing a list of sounds needs llPlaySound with a timer for each clip.

Does a sound loop cause lag?

Very little. The region tells viewers to loop the sound once; the viewer does the rest.

Check your own script: LSL syntax checker →

More scriptsAll scripts
LSL script · 55 lines

LSL door script: touch to open, closes by itself

Free LSL door script for Second Life. Touch to open and close, the door swings on its hinge and closes by itself after a few seconds. Sounds optional.

LSL script · 69 lines

LSL sit and pose script for chairs and pose balls

Free LSL sit script for Second Life chairs, benches and pose balls: sit and play your own animation, set the sit position, hide the ball while in use.

LSL script · 96 lines

LSL tip jar script with thank-you message and total

Free LSL tip jar script for Second Life clubs, DJs, hosts and stores: quick pay buttons, a thank-you message, the total and last tipper in floating text.