Menu
CoddyTech

The Fight Script

Lesson 1 of 20 in Coddy's Roblox Game: Battlegrounds course.

In this course you build a battlegrounds game: a sword, abilities on keys and phone buttons, combos and blocks, and bots that hunt you around the arena.

The game has two scripts. BattleServer, a Script, runs on Roblox's server and owns every rule. BattleClient, a LocalScript in the HUD, runs on each player's device; it holds only a comment until chapter 2. Every number that balances the game is in ReplicatedStorage.Settings.

A sword is a Tool. A player's tools live in their Backpack, and the Backpack is emptied every time they respawn, so the sword is handed out on each CharacterAdded, not once when they join:

player.CharacterAdded:Connect(function()
	local sword = ServerStorage.Sword:Clone()
	sword.Parent = player.Backpack
end)

Press 1 (or tap the sword at the bottom of the screen) to hold it.

challenge icon

Challenge

Easy
  1. Load the settings with require(game.ReplicatedStorage.Settings).
  2. Print Swords deal 10 damage, built from Settings.SwordDamage.
  3. When a player joins, give them a leaderstats Folder with an IntValue named Kills.
  4. On every CharacterAdded, clone ServerStorage.Sword into their Backpack.

Press Play, press 1 to hold the sword, then Check.

Try it yourself

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

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


-- 2. Print how much a sword hit does, using Settings.SwordDamage


-- 3. When a player joins: Kills on the leaderboard (a Folder named
--    leaderstats holding an IntValue), and every time their character
--    spawns, a copy of ServerStorage.Sword in their Backpack
quiz iconTest yourself

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

All lessons in Roblox Game: Battlegrounds