Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do you make a currency leaderboard system?

I've tried every tutorial, I've done everything I can, but can't seem to make a currency system. I'm trying to make a clicker game based on the nursery rhyme "piggy on the railway". The concept is that you (the piggy) collect rocks (the currency) by clicking on the bed of a railroad track and avoid trains, which make you lose all of your stones. So far, I can't seem to find any way to make a currency leaderboard.

1 comment

0

You can check out the default leaderboards here (https://developer.roblox.com/articles/Leaderboards) but you can of course implement your own GUI and way of storing values. It's completely up to you.

1 answer

✓ Accepted answer

This is a currency leaderboard system that saves (Credit to an AlvinBlox Tutorial.)

I have added some notes about how it works in the script. (This script should be in ServerScriptService)

local DataStoreService = game:GetService("DataStoreService")

  

local GameDataStore = DataStoreService:GetDataStore("GameDataStore")

--What happens when the player joins the game.

  
game.Players.PlayerAdded:Connect(function(player)

--Creates leaderstats

local leaderstats = Instance.new("Folder")

leaderstats.Name = "leaderstats"

leaderstats.Parent = player

--Creates the Coins leaderstat.

local Coins = Instance.new("IntValue")

Coins.Name = "Coins"

Coins.Parent = leaderstats

-- This is the part of the script that loads the data when the player joins.

local data

local Success, ErrorMessage = pcall(function()

data = GameDataStore:GetAsync(player.UserId .. "-Coins")

end)

if Success then

Coins.Value = data

else

print("There was an error whilst loading data")

warn(ErrorMessage)

end

end)

  

--What happens when the player leaves the game.

  

game.Players.PlayerRemoving:Connect(function(player)

--This is the part that saves the data when the player leaves.

local Success, ErrorMessage = pcall (function()

GameDataStore:SetAsync(player.UserId.."-Coins",player.leaderstats.Coins.Value)

end)

if Success then

print("Player Data Successfully Saved.")

else

print("There was an error when saving data.")

warn(ErrorMessage)

end

end)

Tutorial which I recommend you follow through yourself: https://www.youtube.com/watch?v=DkYupSBUpes

2 comments

0

okay, and if I change coins.name to "stones", will it work?

0

yes

This discussion is preserved as it was. New answers, comments, and votes are closed.