Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

how do i make a second leaderstat for rebirth?

Asked by 5 years ago
Edited by TheeDeathCaster 5 years ago

im trying to make a rebirth system and i got everything done except i do not know how to make a second leaderstat. So here is my rebirth system...

function Entered(player)
    wait()

    if player:findFirstChild("leaderboard") ~= nil then
        player.leaderstats:remove()
    end

    stats = Instance.new("IntValue")
    stats.Parent = player
    stats.Name = "leaderboard"

    money = Instance.new("IntValue")
    money.Parent = stats
    money.Name = "Rebirths"
    money.Value = 0

end

game.Players.PlayerAdded:connect(Entered)

c = game.Players:GetChildren()
for i=1, #c do
    Entered(c[i])
end

so what do i need to change and how do i change it?

0
I put all code in a code block. TheeDeathCaster 2368 — 5y
0
what is a code block? dottsa_legend 16 — 5y
0
Please make your own scripts Ziffixture 6913 — 5y

3 answers

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

That script is disgusting, and I know good and well you didn't write it. Here's the proper way to make leaderstats. As a note, you just copy the given section to add another row to the leaderboard.


In a Server Script

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player

    local rebirths = Instance.new("IntValue") --this is the section you copy
    rebirths.Name = "Rebirths"
    rebirths.Parent = leaderstats
    -- so if i wanted to add another section, for example called "Cash", I'd do...
    local cash = Instance.new("IntValue")
    cash.Name = "Cash"
    cash.Parent = leaderstats
end)

So everytime a player joins, a folder will be created inside them called leaderstats. To create a built-in ROBLOX leaderboard, you are required to have a Folder or Model inside the player object named leaderstats, otherwise the well-known rows and columns will not be automatically created. To make the rows and columns, we create values inside the data container, such as Rebirths and Cash.

Another thing to note is that the Parent property should always be set last, due to the way ROBLOX changes objects' properties. Read this article for more information.


P.S. Next time you post a question, click the Lua icon on your editor to make a codeblock. Then, put your code within the ~~~'s.

Resources:

ROBLOX Leaderboards


Accept and upvote if this helps!

0
so what do i do if i want 2 leaderstats? (which in this case is Rebirths and AtDollars) dottsa_legend 16 — 5y
0
change the "cash" section to fit your needs. just change line 13 to: cash.Name = "AtDollars" Gey4Jesus69 2705 — 5y
0
okay i get it this helps out even more :) dottsa_legend 16 — 5y
0
ur bad User#24403 69 — 5y
0
I already have the leaderstats and i made the button to rebirth...But i want it when someone purchase the rebirth the amount will double ex.if it is 1 coin than when i purchase it the price of the next rebirth becomes 2 and so on a65654321 0 — 4y
Ad
Log in to vote
2
Answered by 5 years ago
Edited 5 years ago

Well making one leaderstat is essentially the process as making a second leaderstat

game.Players.PlayerAdded:Connect(function(player)
    local stats = Instance.new("Folder")
    stats.Name = "leaderstats"
    stats.Parent = player

    local money = Instance.new("IntValue")
    money.Name = "Money"
    money.Value = 0
    money.Parent = stats

    local rebirth = Instance.new("IntValue")
    rebirth.Name = "Money"
    rebirth.Value = 0
    rebirth.Parent = stats
end)

There are a couple of things you should keep in mind though when making leaderstats and coding in general

  • to make a leaderboard, the object you are housing the leaderstats in has to be named leaderstats,

  • use local variables when you aren't doing to be using it outside of the scope of the function

  • Set the parent property of an object last due to the way roblox handles property listeners

hopefully this helped you out!

0
Excellent answer, upvote for you. 0RKH 35 — 5y
0
but my answer is exactly the same and i posted mine first, plus mine included resources and tips on future posting Gey4Jesus69 2705 — 5y
0
THANK ALL OF YOU!!! after reading all of these awnsers i now know how to do it so thank you so much for helping me out now i can actually get into the new areas and stuff! dottsa_legend 16 — 5y
0
but last thing how do i make a folder... dottsa_legend 16 — 5y
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

Firstly, you don't even need to get the children of the player to fire the Entered event.

Secondly, to get the leaderboard to appear, it must be a variable inside the player, as you did, but must be named "leaderstats" and be a Model or a Folder

game.Players.PlayerAdded:Connect(function(player)
    local stats = Instance.new("Folder", player)
    stats.Name = "leaderstats"

    local points  = Instance.new("IntValue", stats)
    points.Name = "Points"

    local rebirths = Instance.new("IntValue", stats)
    rebirths.Name = "Rebirths"
    rebirths.Value = 0
end)

Since you want two values, you simply have to define a new Instance.new event after the first one.

It is best to define a new name for each value so you can call them later in another function.

0
help was useful :) dottsa_legend 16 — 5y

Answer this question