Menu
CoddyTech

Coin Piles

Lesson 2 of 18 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
  1. Near the top: local ServerStorage = game:GetService("ServerStorage") and local piles = workspace.Piles.
  2. Write spawnPile(spot): clone ServerStorage.CoinPile, put it at the spot's Position, set its attributes MaxHealth and Health to Settings.PileHealth and Value to Settings.PileValue, parent it to piles and return it.
  3. Call it for every spot in workspace.Zones.Meadow.Spawns.

Press Play: gold piles 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)
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Roblox Game: Pet Simulator