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")) --> 3Every copy carries its own attributes, so each pile has its own health.
Challenge
EasyPut a coin pile on every spot in the Meadow.
- Near the top:
local ServerStorage = game:GetService("ServerStorage")andlocal piles = workspace.Piles. - Write
spawnPile(spot): cloneServerStorage.CoinPileto the spot's Position; attributesMaxHealthandHealth=Settings.PileHealth,Value=Settings.PileValue; parent it topiles; return it. - 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