On this page
To make a simulator game on Roblox, build one loop: players click to earn coins, spend coins on eggs, hatch pets that multiply their earnings, then rebirth for a permanent boost. The server owns every number in that loop. It counts clicks, rolls eggs and stores pets, and the client only shows the results.
The simulator loop
- Click to earn coins.
- Spend coins on an egg.
- Hatch a random pet. Rarer pets give bigger boosts.
- Equip your best pets so every click earns more.
- Rebirth: reset coins for a permanent multiplier and go again, faster.
Still picking a theme? These Roblox game ideas include simulator twists that go beyond clicking.
The scripts below find things by name, so create these first:
- In ReplicatedStorage: RemoteEvents named Click, EquipPet and Rebirth, a ModuleScript named Eggs, and a Folder named PetModels with one Model per pet.
- In Workspace: a Folder named EggStands with one model per egg, named after it (such as Basic), each with a ProximityPrompt and a BillboardGui holding a TextLabel named Odds.
Save coins, rebirths and the pet inventory
Every other script reads this data, so set it up first. Each pet is a StringValue in a Pets folder under the player: its name is a unique id, its value is the pet type, and an Equipped attribute says whether it's out.
-- Script in ServerScriptService: loads and saves Coins, Rebirths and the pet inventory
local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local store = DataStoreService:GetDataStore("SimulatorData1")
local loaded = {}
local function onPlayerAdded(player)
local ok, data = pcall(function()
return store:GetAsync("player_" .. player.UserId)
end)
if not ok then warn("Could not load " .. player.Name .. ", this session will not save") end
if not player.Parent then return end -- left while loading
data = (ok and data) or {}
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
for _, statName in { "Coins", "Rebirths" } do
local stat = Instance.new("IntValue")
stat.Name = statName
stat.Value = data[statName] or 0
stat.Parent = leaderstats
end
leaderstats.Parent = player
local pets = Instance.new("Folder")
pets.Name = "Pets"
for _, saved in data.Pets or {} do
local pet = Instance.new("StringValue")
pet.Name = saved.Id
pet.Value = saved.Name
pet:SetAttribute("Equipped", saved.Equipped == true)
pet.Parent = pets
end
pets.Parent = player
loaded[player] = ok
end
local function save(player)
if not loaded[player] then return end
local stats = player.leaderstats
local data = { Coins = stats.Coins.Value, Rebirths = stats.Rebirths.Value, Pets = {} }
for _, pet in player.Pets:GetChildren() do
table.insert(data.Pets, { Id = pet.Name, Name = pet.Value, Equipped = pet:GetAttribute("Equipped") == true })
end
local ok, err = pcall(function()
store:UpdateAsync("player_" .. player.UserId, function()
return data
end)
end)
if not ok then warn("Could not save " .. player.Name .. ": " .. tostring(err)) end
end
Players.PlayerAdded:Connect(onPlayerAdded)
for _, player in Players:GetPlayers() do task.spawn(onPlayerAdded, player) end
Players.PlayerRemoving:Connect(function(player)
save(player)
loaded[player] = nil
end)
game:BindToClose(function()
for _, player in Players:GetPlayers() do task.spawn(save, player) end
task.wait(3)
end)The script loads one table on join and rebuilds leaderstats and the Pets folder from it. On leave and shutdown, it turns the folder back into a table and saves it with UpdateAsync inside pcall. If the load fails, that session never saves, so a hiccup can't overwrite someone's pets with an empty list. The DataStore tutorial adds retries and autosaving.
Earn coins with clicks the server checks
The client only reports that a click happened. The server decides what it's worth and ignores clicks that come too fast:
-- Script in ServerScriptService: turns clicks into coins, with a rate limit and pet boosts
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Eggs = require(ReplicatedStorage:WaitForChild("Eggs"))
local clickEvent = ReplicatedStorage:WaitForChild("Click")
local COINS_PER_CLICK = 5
local lastClick = {}
local function getMultiplier(player)
local petBonus = 0
for _, pet in player.Pets:GetChildren() do
if pet:GetAttribute("Equipped") then
petBonus += Eggs.Boosts[pet.Value] or 0
end
end
local rebirthBonus = player.leaderstats.Rebirths.Value * 0.5
return (1 + petBonus) * (1 + rebirthBonus)
end
clickEvent.OnServerEvent:Connect(function(player)
local now = os.clock()
if not player:FindFirstChild("Pets") or now - (lastClick[player] or 0) < 0.1 then
return
end
lastClick[player] = now
player.leaderstats.Coins.Value += math.floor(COINS_PER_CLICK * getMultiplier(player))
end)
Players.PlayerRemoving:Connect(function(player)
lastClick[player] = nil
end)Then put a TextButton in a ScreenGui in StarterGui, with this LocalScript inside the button:
-- LocalScript inside a TextButton in a ScreenGui: tells the server about each click
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local clickEvent = ReplicatedStorage:WaitForChild("Click")
script.Parent.Activated:Connect(function()
clickEvent:FireServer()
end)Activated fires for mouse clicks, taps and gamepad presses, so one button covers every device. The server accepts at most ten clicks a second, so an auto-clicker can't flood it. The pet boosts come from the Eggs module, which you fill in next.
Eggs and a weighted rarity table
Each egg lists its pets with a weight. A pet's chance is its weight divided by the egg's total weight. Weights are easier to tune than percentages: add a pet and every other chance adjusts on its own.
-- ModuleScript named Eggs in ReplicatedStorage: pet boosts, egg prices and hatch weights
local Eggs = {}
-- What each pet adds to earnings: 0.25 means +25%
Eggs.Boosts = { Cat = 0.25, Dog = 0.5, Fox = 1, Dragon = 6 }
Eggs.List = {
Basic = {
Price = 250,
Pets = {
{ Name = "Cat", Weight = 60 },
{ Name = "Dog", Weight = 30 },
{ Name = "Fox", Weight = 9 },
{ Name = "Dragon", Weight = 1 },
},
},
-- Add more eggs the same way, each pricier with stronger pets
}
return EggsBoosts lives apart from the eggs, so one pet can appear in several eggs and you rebalance it in one place, even for pets players already own. Players should see the odds before they spend, so this script writes them on each stand:
-- Script in ServerScriptService: writes each egg's price and chances on its stand
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Eggs = require(ReplicatedStorage:WaitForChild("Eggs"))
for _, stand in workspace:WaitForChild("EggStands"):GetChildren() do
local egg = Eggs.List[stand.Name]
local label = stand:FindFirstChild("Odds", true)
if egg and label then
local total = 0
for _, entry in egg.Pets do
total += entry.Weight
end
local lines = { egg.Price .. " coins" }
for _, entry in egg.Pets do
table.insert(lines, string.format("%s %.1f%%", entry.Name, entry.Weight / total * 100))
end
label.Text = table.concat(lines, "\n")
end
endHatch and equip on the server
One server script handles buying, rolling and equipping:
-- Script in ServerScriptService: hatches eggs (rolled here, never on the client) and equips pets
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local HttpService = game:GetService("HttpService")
local Eggs = require(ReplicatedStorage:WaitForChild("Eggs"))
local equipEvent = ReplicatedStorage:WaitForChild("EquipPet")
local rng = Random.new()
local MAX_PETS, MAX_EQUIPPED = 200, 3
local function roll(egg)
local total = 0
for _, entry in egg.Pets do total += entry.Weight end
local pick = rng:NextNumber() * total
for _, entry in egg.Pets do
pick -= entry.Weight
if pick < 0 then return entry.Name end
end
return egg.Pets[#egg.Pets].Name
end
local function hatch(player, eggName)
local egg = Eggs.List[eggName]
local stats, pets = player:FindFirstChild("leaderstats"), player:FindFirstChild("Pets")
if not egg or not pets or stats.Coins.Value < egg.Price or #pets:GetChildren() >= MAX_PETS then
return
end
stats.Coins.Value -= egg.Price
local pet = Instance.new("StringValue")
pet.Name = HttpService:GenerateGUID(false)
pet.Value = roll(egg)
pet.Parent = pets
end
for _, stand in workspace:WaitForChild("EggStands"):GetChildren() do
local prompt = stand:FindFirstChildWhichIsA("ProximityPrompt", true)
if prompt then
prompt.Triggered:Connect(function(player)
hatch(player, stand.Name)
end)
end
end
equipEvent.OnServerEvent:Connect(function(player, petId, equip)
local pets = player:FindFirstChild("Pets")
local pet = pets and typeof(petId) == "string" and pets:FindFirstChild(petId)
if not pet then return end
if equip == true then
local count = 0
for _, other in pets:GetChildren() do
if other:GetAttribute("Equipped") then count += 1 end
end
if count >= MAX_EQUIPPED then return end
end
pet:SetAttribute("Equipped", equip == true)
end)An egg's ProximityPrompt fires on the server with the player who used it, so hatching needs no RemoteEvent. The server checks the price and inventory space, takes the coins, rolls the pet and adds it to the Pets folder. The roll subtracts weights from a random number until it drops below zero, so a weight of 1 out of 100 lands 1% of the time.
Equipping checks that the pet belongs to that player and that fewer than three are out. Your inventory UI calls EquipPet:FireServer(pet.Name, true) and never edits the folder itself.
Pets that follow the player
Ownership lives on the server, but following is pure visuals, so each client draws everyone's pets itself. Movement stays smooth and the server does no work:
-- LocalScript in StarterPlayerScripts: draws every player's equipped pets and makes them follow
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local petModels = ReplicatedStorage:WaitForChild("PetModels")
local shown = {} -- [pet value] = the model this client draws for it
local function check(pet)
local template = petModels:FindFirstChild(pet.Value)
if pet:GetAttribute("Equipped") and template and not shown[pet] then
local model = template:Clone()
for _, part in model:GetDescendants() do
if part:IsA("BasePart") then
part.Anchored = true
part.CanCollide = false
end
end
model.Parent = workspace
shown[pet] = model
end
end
local function watchPet(pet)
check(pet)
pet:GetAttributeChangedSignal("Equipped"):Connect(function() check(pet) end)
end
local function watchPlayer(player)
local pets = player:WaitForChild("Pets")
for _, pet in pets:GetChildren() do watchPet(pet) end
pets.ChildAdded:Connect(watchPet)
end
Players.PlayerAdded:Connect(watchPlayer)
for _, player in Players:GetPlayers() do task.spawn(watchPlayer, player) end
RunService.RenderStepped:Connect(function(dt)
local slots = {}
for pet, model in shown do
if not pet:GetAttribute("Equipped") or not pet:IsDescendantOf(Players) then
model:Destroy()
shown[pet] = nil
continue
end
local player = pet.Parent.Parent
local root = player.Character and player.Character:FindFirstChild("HumanoidRootPart")
if root then
slots[player] = (slots[player] or 0) + 1
local slot = slots[player]
local bob = math.sin(os.clock() * 3 + slot) * 0.4
local goal = root.CFrame * CFrame.new((slot - 2) * 3, 1 + bob, 5)
model:PivotTo(model:GetPivot():Lerp(goal, math.min(dt * 8, 1)))
end
end
end)For every player, the script watches the Pets folder and clones a model from PetModels when a pet is equipped. Each frame it eases every model toward a slot behind its owner, with a small bob, and deletes models whose pet was unequipped or whose owner left. Because a LocalScript made the clones, they exist only on that client.
No pet models yet? Revix can build a set in your game's style and put them in PetModels.
Stacking multipliers
The click script multiplies two groups: (1 + pet boosts) * (1 + 0.5 per rebirth). Inside a group, boosts add. Between groups, they multiply.
Here is why. Three equipped Foxes add 1 each, so the pet group is x4. Two rebirths make the rebirth group x2. Together that's x8, so a 5 coin click pays 40.
If every pet multiplied instead, three Dragons would give 7 x 7 x 7 = x343, and your egg prices would stop meaning anything. Adding gives x19: big, but still something you can price. Add a new group, such as a double coins game pass, only when you want a separate, deliberate jump.
Rebirths and balancing the numbers
-- Script in ServerScriptService: rebirths reset coins for a permanent multiplier
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local rebirthEvent = ReplicatedStorage:WaitForChild("Rebirth")
local BASE_COST = 10000
rebirthEvent.OnServerEvent:Connect(function(player)
local stats = player:FindFirstChild("leaderstats")
if not stats then return end
local cost = BASE_COST * 2 ^ stats.Rebirths.Value
if stats.Coins.Value >= cost then
stats.Coins.Value = 0
stats.Rebirths.Value += 1
end
end)Fire the Rebirth event from a button, the same way as Click. Only coins reset; players keep their pets. It's the same idea as rebirths in a tycoon, but simulators lean on it harder. The cost doubles each time while each rebirth adds only 0.5 to the multiplier, so the wait grows steadily:
| Rebirth | Cost | Multiplier while saving up | Time at 50 coins a second |
|---|---|---|---|
| 1st | 10,000 | x1 | 3.3 minutes |
| 2nd | 20,000 | x1.5 | 4.4 minutes |
| 3rd | 40,000 | x2 | 6.7 minutes |
| 4th | 80,000 | x2.5 | 10.7 minutes |
| 5th | 160,000 | x3 | 17.8 minutes |
That assumes 50 coins a second before multipliers and no new pets. Better pets shorten every wait, and that's the point: pets should feel like the fast lane.
A few rules keep the numbers healthy:
- Price each egg around 20 times the one before, and make its best pets a few times stronger.
- Let the time to the next goal grow slowly, about 1.5 times per step, as in the table.
- If players rebirth too fast, raise
BASE_COST. If they stall, lower the 2 in the formula to something like 1.7.
Questions
How do you make an egg hatching system in Roblox?
Give each egg a list of pets with weights and roll on the server when a player buys one: pick a random number below the total weight, then walk the list subtracting weights until it runs out. Charge the coins, add the pet to the player's inventory and let the client play the hatch effect.
How do pet rarities work?
Each pet in an egg has a weight, and its chance is its weight divided by the total of all the weights in that egg. A pet with weight 1 in an egg that totals 100 has a 1% chance. Show these chances on the egg so players know what they are paying for.
How do you make pets follow the player in Roblox?
The server stores which pets are equipped, and a LocalScript on every client draws those pets and moves them toward a spot behind each character every frame. Running the movement on clients keeps it smooth and keeps the server free for gameplay.
How do you save pets in a DataStore?
Turn the inventory into a plain table of pet ids, pet names and equipped flags, and save it with UpdateAsync inside pcall when the player leaves and when the server shuts down. Rebuild the inventory from that table when they join again.
How does a rebirth system work?
A rebirth resets coins in exchange for a permanent multiplier, and its cost grows each time, for example by doubling. The server checks the cost, resets the coins and adds one to Rebirths, which the earnings formula reads.








