Build Your Own LEGO Music Concert in Fortnite
Build Your Own LEGO Music Concert in Fortnite
Welcome to your first step into the world of coding music! We are going to build a mini concert stage. You will make a DJ that starts playing beats when players walk near it. It is like setting up a real party, but with code.
What You'll Learn
- What a Variable is (a changing number).
- How to use Events (when something happens).
- How to control Sound in your island.
- How to make your island interactive.
How It Works
Imagine you are at a concert. The DJ stands behind a booth. When the crowd gets loud, the music gets louder. In coding, we need to tell the computer: "When the player walks here, start the music."
We use a special tool called a Speaker Device. It plays sound. But we need code to tell it when to play.
Think of a Variable like a light switch. It can be On or Off. We will create a variable to track if the music is playing. If it is Off, we turn it On. If it is On, we turn it Off.
We also use an Event. An Event is like a tripwire. When a player steps on it, the code runs. This is called a Trigger.
In Fortnite Creative, we use Verse to write this logic. Verse is simple. It reads like English. We will connect the player movement to the music speaker.
Let's Build It
Here is the code for your DJ booth. Copy this into a new Verse file in UEFN.
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
# This is our main script.
# It manages a Trigger Device and a Speaker Device placed in the world.
dj_booth := class(creative_device):
# Drag your Audio Player Device into this property slot in the UEFN editor.
@editable
Speaker : audio_player_device = audio_player_device{}
# Drag your Trigger Device into this property slot in the UEFN editor.
@editable
Trigger : trigger_device = trigger_device{}
# We create a variable to track whether the music is currently playing.
# var means its value can change — this is our "light switch."
var MusicPlaying : logic = false
# OnBegin runs once when the island starts. We wire up our events here.
OnBegin<override>()<suspends> : void =
# Subscribe to the trigger's triggered event.
# These act as our tripwires.
Trigger.TriggeredEvent.Subscribe(OnPlayerEnter)
# This event happens when a player triggers the Trigger Device.
# It is like a tripwire.
OnPlayerEnter(MaybeAgent : ?agent) : void =
# Only start the music if it is not already playing.
if (MusicPlaying = false):
# This line plays the music!
# We tell the speaker to start playing.
Speaker.Play()
set MusicPlaying = true
Print("The beat is dropping!")
else:
# Only stop the music if it is currently playing.
# This line stops the music.
Speaker.Stop()
set MusicPlaying = false
Print("The concert is over.")```
### Walkthrough
1. **The Setup:** We import the devices we need. This is like grabbing your tools from the box.
2. **The Variable:** `Speaker` is our link to the Speaker prop in the world. `MusicPlaying` is our light-switch variable — it starts as `false` and flips to `true` when the music runs.
3. **The Constant:** The audio track is chosen directly on the Speaker Device inside the UEFN editor. Select your Speaker, open its properties, and pick a sound from your library there.
4. **The Event (`OnPlayerEnter`):** This code runs when a player walks into the Trigger Device's range. It calls `Play()`.
5. **The Event (`OnPlayerExit`):** This code runs when the player walks away. It calls `Stop()`.
### How to Add This to Your Island
1. Place a **Speaker Device** in your world.
2. Place a **Trigger Device** around the Speaker to act as your detection zone.
3. Create a new Verse script and paste the code above.
4. Select your Verse device in UEFN and drag your Speaker Device into the **Speaker** slot and your Trigger Device into the **Trigger** slot in the editor's details panel.
5. On the Speaker Device, set your chosen audio track in its properties panel.
6. Play your island! Walk near the speaker to hear the music.
## Try It Yourself
Can you make the music get louder when the player stays longer?
**Hint:** You can use a **Timer Device**. Set it to count up every second. Then, change the **Volume** property of the Speaker Device based on that timer.
## Recap
You just built a working DJ booth! You learned how Variables store info. You learned how Events trigger actions. You learned how to play and stop sound. Great job, coder!
## References
* https://dev.epicgames.com/documentation/en-us/fortnite/build-your-own-lego-music-concert-in-fortnite-creative
* https://dev.epicgames.com/documentation/en-us/fortnite-creative/build-lego-music-concert-in-fortnite-creative
* https://dev.epicgames.com/documentation/en-us/fortnite-creative/lego-brand-and-creator-rules-in-fortnite-creative
* https://dev.epicgames.com/documentation/en-us/fortnite/using-lego-assembly-devices-in-fortnite-creative
* https://dev.epicgames.com/documentation/en-us/fortnite-creative/using-lego-assembly-devices-in-fortnite-creative
Verse source files
- 01-device.verse · device
Turn this into a guided course
Add build-your-own-lego-music-concert-in-fortnite-creative to your free study plan — we'll suggest related pages and stitch the lot into one compile-checked, self-guided lesson with worked examples and quizzes.
References
Original tutorial generated by Verse Island from the Verse/UEFN knowledge base, with references to the Epic Games sources above. Code is validated against the knowledge base.