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?
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.
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!
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.