Menu
CoddyTech

Coin Piles

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

Coins come from piles. The Meadow has eight spots for them, invisible parts in workspace.Zones.Meadow.Spawns, and ServerStorage.CoinPile is the pile itself, waiting where players never see it.

To put a pile on a spot, clone the template and move the copy there. Each pile also needs to remember its health and what it is worth. Attributes keep values like that on the instance itself:

pile:SetAttribute("Health", 3)
print(pile:GetAttribute("Health")) --> 3

Every copy carries its own attributes, so each pile has its own health.

challenge icon

Challenge

Easy

Put a coin pile on every spot in the Meadow.

  1. Near the top: local ServerStorage = game:GetService("ServerStorage") and local piles = workspace.Piles.
  2. Write spawnPile(spot): clone ServerStorage.CoinPile to the spot's Position; attributes MaxHealth and Health = Settings.PileHealth, Value = Settings.PileValue; parent it to piles; return it.
  3. Call it for every spot in workspace.Zones.Meadow.Spawns.

Press Play: gold piles stand on the grass. Then Check.

Try it yourself

local Players = game:GetService("Players")
local Settings = require(game.ReplicatedStorage.Settings)

print("A Meadow pile gives " .. Settings.PileValue .. " coins")

-- Every player gets Coins on the leaderboard
Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player

	local coins = Instance.new("IntValue")
	coins.Name = "Coins"
	coins.Parent = leaderstats
end)

-- Lesson 2: Coin Piles goes here

All lessons in Roblox Game: Pet Simulator

Practice on your own: Roblox playground