Menu
CoddyTech

The Fight Script

Lesson 1 of 25 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

Start the fight script, BattleServer, and hand out a sword.

  1. Load the settings: local Settings = require(game.ReplicatedStorage.Settings).
  2. Print "Swords deal " .. Settings.SwordDamage .. " damage".
  3. In Players.PlayerAdded, on every player.CharacterAdded, clone ServerStorage.Sword into player.Backpack.

Press Play and press 1: the Output reads Swords deal 10 damage and you hold a 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: every time their character spawns, put a
--    copy of ServerStorage.Sword in their Backpack

All lessons in Roblox Game: Battlegrounds

Practice on your own: Roblox playground