Reputation: 21
How do I make a Leaderboard on roblox?
Upvotes: -2
Views: 25486
Reputation: 1
Insert a script into ServerScriptService and paste down the following code:
plrEntered = function(player)
local ls = Instance.new('Folder') --Leaderstats
ls.Parent = player
ls.Name = 'leaderstats'
local stat = Instance.new('IntValue', ls)
stat.Name = 'Money' -- Change to the value you want
stat.Value = 0 -- Add the starting value
end
game:GetService("Players").PlayerAdded:Connect(plrEntered)
Upvotes: 0
Reputation: 1
you first have to make a script inside the server script service and name it what ever you want, and write this in the script (make sure its normal script not local)
game:GetService("Players").PlayerAdded:Connect(function() --make the function start when new player joins
local player = game.Players.PlayerAdded --make player variable
local leaderstats = instance.new("Folder", player) --make new folder and set it's parent to the player
local money = instance.new("IntValue", leaderstats) --create new value for the stat and set it's parent to the leaderstats folder (you can create as many as u want)
money.name = "Money" --make the name of the value
money.Value = 0 --make the value's value
end)
this block of code is simple and has many comments to explain it I wish it was helpful.
Upvotes: 0
Reputation: 1
function stats(plr)
local leaderstats = Instance.new("IntValue")
leaderstats.Name = "leaderstats"
leaderstats.Parent = plr
local coins = Instance.new("IntValue")
Coins.Name = "coins"
Coins.Parent = leaderstats
end)
game.Players.PlayyerAdded:Connect(stats)
Upvotes: -1
Reputation: 1
function Onplayererntered(player)
local leaderstats = Instance.new("IntValue")
leaderstats.Pareny = player
leaderstats.Value = 0
leaderstats.Name = "leaderboard"
local stat = Instance.new("IntValue")
statname = "Cash"
stat.Value = 100
end
Upvotes: 0
Reputation: 21
Insert a script into workspace, then in the code type this:
function Onplayerentered(player)
local leaderstats = Instance.new("IntValue")
leaderstats.Parent = player
leaderstats.Value = 0
leaderstats.Name = "leaderstats"
local stat = Instance.new("IntValue")
stat.Name = "" -- Put name here in between the quotations
stat.Value = -- Put the starting Value#
end
game:GetService("Players").ChildAdded:Connect(Onplayerentered)
Upvotes: 2
Reputation:
ROBLOX defines a leaderboard as an object that is named as 'leaderstats' and is located in the player object. A leaderboard statistic is defined as a value object inside the leaderstats object (Player>leaderstats>ValueObject). So lets write a function that creates a leaderboard with a 'cash' statistic for a player.
local function createLeaderboard(player)
local stats = Instance.new("Folder")
stats.Name = "leaderstats"
local cash = Instance.new("IntValue", stats)
cash.Name = "Cash"
stats.Parent = player
end
Then we need to make this work. We need to connect this function to the 'PlayerAdded' event from the 'Players' object.
local players = game:WaitForChild("Players")
players.PlayerAdded:connect(createLeaderboard)
And that is basically it. Note that line 3 in the code shown directly above is the equivalent of:
players.PlayerAdded:connect(function(player)
createLeaderboard(player)
end)
The entire script would look like this:
local players = game:WaitForChild("Players")
local function createLeaderboard(player)
local stats = Instance.new("Folder")
stats.Name = "leaderstats"
local cash = Instance.new("IntValue", stats)
cash.Name = "Cash"
stats.Parent = player
end
players.PlayerAdded:connect(createLeaderboard)
It is recommended to put the script in the 'ServerScriptService'.
Upvotes: 0
Reputation: 21
Roblox leaderboards is a very long script, thankfully, the script allow us to easily add and remove leaderstats. To add a leaderboard insert a IntValue inside of the player object, to add a stat insert a IntValue inside the leadestats.
Most games on Roblox want every player to have the same leaderboard. So most people use a PlayerAdded event and create the leaderboard
Upvotes: 0
Reputation: 4305
In every player needs to be inserted a value called 'leaderstats', using a script with the PlayerAdded event. Inside the leaderstats value, you can place IntValues - their name is what will show as the heading, and their value is what will appear as the player's stat.
To make those stats change, you need to add different functions and/or events to the script that created the leaderstats values.
Upvotes: 2
Reputation: 1
Upvotes: 0