Menu
CoddyTech

The Defense Script

Lesson 1 of 18 in Coddy's Roblox Game: Tower Defense course.

In this course you build a tower defense game: enemies march along a path in waves, and you stop them with towers you buy, place, upgrade and sell before they reach your base.

The game has two scripts. DefenseServer, a Script, runs on Roblox's server and owns every rule: the enemies, the money, the base. DefenseClient, a LocalScript inside the HUD, runs on each player's device and draws their screen. Its file is a note until chapter 2.

Every number that balances the game is in one ModuleScript, ReplicatedStorage.Settings, so you can tune the whole game from one place:

local Settings = require(game.ReplicatedStorage.Settings)
print(Settings.BaseHealth) --> 20
challenge icon

Challenge

Easy

Your DefenseServer Script is in ServerScriptService.

  1. Load the settings with require(game.ReplicatedStorage.Settings).
  2. Print The base can take 20 hits, built from Settings.BaseHealth.
  3. When a player joins, give them a leaderstats Folder holding an IntValue named Money that starts at Settings.StartMoney.

Press Play, then Check.

Try it yourself

-- DefenseServer: the Script that runs the game, on the server.
local Players = game:GetService("Players")

-- 1. Load the settings: require the ModuleScript
--    game.ReplicatedStorage.Settings


-- 2. Print how many hits the base can take, using Settings.BaseHealth


-- 3. Give every player Money on the leaderboard, starting at
--    Settings.StartMoney (a Folder named leaderstats holding an IntValue)
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Roblox Game: Tower Defense