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")) --> 3Every copy carries its own attributes, so each pile has its own health.
Challenge
Easy- Near the top:
local ServerStorage = game:GetService("ServerStorage")andlocal piles = workspace.Piles. - Write
spawnPile(spot): cloneServerStorage.CoinPile, put it at the spot's Position, set its attributesMaxHealthandHealthtoSettings.PileHealthandValuetoSettings.PileValue, parent it topilesand return it. - 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)
This lesson includes a short quiz. Start the lesson to answer it and track your progress.