The Pet Script
Lesson 1 of 18 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(Settings.PileValue) --> 5Challenge
EasyYour PetServer Script is in ServerScriptService.
- Load the settings with
require(game.ReplicatedStorage.Settings). - Print
A Meadow pile gives 5 coins, built fromSettings.PileValue. - When a player joins, give them a
leaderstatsFolder holding an IntValue namedCoins.
Press Play, 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)
This lesson includes a short quiz. Start the lesson to answer it and track your progress.