Exercise 1.3 – Understanding a script
In this exercise, we will insert a script into our game to understand what it does. This script will be given to you in this exercise. It is recommended that you look at this script and recreate it. Try not to copy and paste the script from the GitHub page for this book, as you will learn less by doing this.
Follow these steps:
- Open a new baseplate in Roblox Studio.
- Create a new script in ServerScriptService.
- Inside the previously made script, insert the following code:
local spawnLocation = workspace.SpawnLocation if spawnLocation.Position.X == 0 and spawnLocation.Position.Z == 0 then print("Spawn is in the center!") else print("Spawn is not in the center.") end
- Start playing the game. If you do not move
SpawnLocation
, a Spawn is in the center! message should appear. - Next, move
SpawnLocation
by using the Move tool in the Home section. Did the message change?
Figure 1.5 – Moving SpawnLocation
- What happens when you place
SpawnLocation
in the center and change the height? Why does this happen?
The code used in this exercise can be found on the GitHub page for this book: https://github.com/PacktPublishing/Mastering-Roblox-Coding/tree/main/Exercises.