The Tycoon Script
Lesson 1 of 22 in Coddy's Roblox Game: Factory Tycoon course.
In this course you build a tycoon, one of the most played kinds of Roblox game. Machines drop ore, a conveyor carries it to a collector, the collector pays Cash, and Cash buys more machines. By the end you have a full factory with upgrades, rebirths and saves.
The whole factory runs from one Script in ServerScriptService, called Tycoon. The numbers that balance the game (what ore is worth, how often it drops) live in a ModuleScript, ReplicatedStorage.Settings, and require hands you the table it returns:
local Settings = require(game.ReplicatedStorage.Settings)
print("A drop every " .. Settings.DropInterval .. " second") --> A drop every 1 secondBalancing a tycoon means changing those numbers again and again, so they live in one place.
Cash shows on the leaderboard the way any stat does: a Folder named leaderstats in the player, holding a value:
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local gems = Instance.new("IntValue")
gems.Name = "Gems"
gems.Parent = leaderstatsChallenge
EasyStart the factory's Script, Tycoon, in ServerScriptService.
- Load the settings:
local Settings = require(game.ReplicatedStorage.Settings). - Print
"Ore is worth " .. Settings.OreValue .. " Cash". - When a player joins, give them a
leaderstatsFolder holding an IntValue namedCash.
Press Play: the Output reads Ore is worth 10 Cash, and Cash shows on the leaderboard. Then Check.
Try it yourself
-- Tycoon: the Script that runs your whole factory.
local Players = game:GetService("Players")
-- 1. Load the settings: require the ModuleScript
-- game.ReplicatedStorage.Settings
-- 2. Print what one ore is worth, using Settings.OreValue
-- 3. Give every player a Cash value on the leaderboard
-- (a Folder named leaderstats holding an IntValue named Cash)
All lessons in Roblox Game: Factory Tycoon
Practice on your own: Roblox playground