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

how do i make a second leaderstat for rebirth?

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?

4 comments

0

I put all code in a code block.

0

what is a code block?

0

Please make your own scripts

3 answers

✓ Accepted answer

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!

5 comments

0

so what do i do if i want 2 leaderstats? (which in this case is Rebirths and AtDollars)

0

change the "cash" section to fit your needs. just change line 13 to: cash.Name = "AtDollars"

0

okay i get it this helps out even more :)

0

ur bad

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

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!

4 comments

0

Excellent answer, upvote for you.

0

but my answer is exactly the same and i posted mine first, plus mine included resources and tips on future posting

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!

0

but last thing how do i make a folder...

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.

1 comment

0

help was useful :)

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