Menu
CoddyTech

The Pet Script

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

In this course you build a pet simulator: break coin piles, hatch eggs, collect pets that follow you and dig faster, open a new zone, and keep it all saved.

This game has two scripts. PetServer, a Script, runs on Roblox's server: it owns the coins, the pets and every rule. PetClient, a LocalScript inside the HUD, runs on each player's own device and draws their screen. You meet the client in chapter 2; for now its file only holds a note.

The numbers that balance the game live in a ModuleScript, ReplicatedStorage.Settings:

local Settings = require(game.ReplicatedStorage.Settings)
print("An egg costs " .. Settings.EggPrice) --> An egg costs 25
challenge icon

Challenge

Easy

Start the game's server Script, PetServer.

  1. Load the settings: local Settings = require(game.ReplicatedStorage.Settings).
  2. Print "A Meadow pile gives " .. Settings.PileValue .. " coins".
  3. When a player joins, give them a leaderstats Folder holding an IntValue named Coins.

Press Play: the Output shows A Meadow pile gives 5 coins, and Coins appears on the leaderboard. Then Check.

Try it yourself

-- PetServer: 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 what a Meadow pile gives, using Settings.PileValue


-- 3. Give every player a Coins value on the leaderboard
--    (a Folder named leaderstats holding an IntValue named Coins)

All lessons in Roblox Game: Pet Simulator

Practice on your own: Roblox playground