PcoWSkbVqDnWTu_dm2ix

Adding Scripts

Adding Scripts

Time to bring all this work together! Now that you’ve created the beam and particle components, you’ll add in three premade scripts. These scripts manage the tutorial by telling components when to do what. For example, the scripts will create beams for new players and emit particles whenever they interact with goals

While you can follow all these steps even if you haven’t coded before, having that knowledge can help you adapt these scripts for your own experience. To learn more, see the Basic Coding course.


Store Beam and Particles

Before adding the scripts, the beam and particles need to be moved to where the scripts will be able to make copies of them as needed.

Naming Matters for the Script

The scripts added later will reference the objects named exactly as in this tutorial. If you’re using your own project, you may need to replace the values within some scripted variables to match your objects.


  1. In ReplicatedStorage, create a new folder named PlayerTutorial. Move TutorialBeam out of TestPlayer, and into the new folder.
  1. In ServerStorage, create a folder named TutorialParticles. Move the Burst particle out of TestPlayer into that folder.
  1. Once the beam and particle emitter are moved, you no longer need the TestPlayer. Delete TestPlayer since the script will work with real players when finished.

Create Events

Each time players interact with a goal, the tutorial script will need to know so it can update that player’s progress and emit the particle effect. To inform scripts, signals can be sent using events.

  1. In ReplicatedStorage > PlayerTutorial, create two RemoteEvent objects. Name them NextGoal and TutorialEnd.

Events are a fundamental part of coding in Roblox games. While this course doesn’t go in-depth on events, you can learn more in the Remote Functions and Events article.


Add the Scripts

The three scripts below will look for the particle emitter and beam objects created earlier and manage the tutorial system.

  1. In ReplicatedStorage > PlayerTutorial > create a new ModuleScript named TutorialManager.
Replace the default code by copying and pasting the entire code below.
This script runs code for managing a player's progress in the tutorial. This includes tasks like running code for interacting with goals, or what happens when the tutorial is over.
  1. In ServerScriptService, create a new Script named TutorialParticles.
Paste the code below.
This script plays the burst particle whenever players interact with goals. There's also a variable named EMIT_RATE that determines how many particles spawn during an interaction.
  1. In StarterPlayer > StarterPlayerScripts, create a new LocalScript named TutorialScript.
Then, paste the script below.
This script creates and manages the beam used to guide players.
  1. Play the project to test the scripts. Move from booth to booth, using the interact feature to see if code works.

Issue: Particles play when game starts.
Go into ServerStorage > Tutorial Particles > Burst. Check Enabled to be off.

Issue: Warnings in the compiler such as an “infinite yield”.
Because the script is looking for specific objects in certain locations, it’s possible that a part is named incorrectly. Double check that the name and location of each part in game matches the tutorial.


If you’re using this tutorial system in your experience, keep in mind the following:

Benefits

  • Events such as TutorialEnd can be used to trigger other scripts. For instance, you can award players a special item when this event fires.
  • The TutorialParticles script can play multiple particles at once. You can add more particles in ServerStorage/TutorialParticles for more complex effects.

Limitations:

  • Player progress in the tutorial is not persistent, meaning you’ll have to code some way of saving that progress. For guidance, see the article: Saving Data.


Previous Using Particles for Actions Next Next Steps