Need help with my Leaderstats

So basically I’m making a Leader Board that’s going to show your Money and your Mileage but I don’t know how to add the Mileage part.

I tried this but it didn’t work all did was remove the money and add Miles by itself.
local currencyName = “Money”
local currencyName = “Miles”

Do I need to do a separate script or what. If you know please help me

1 Like

I’m guessing you just want another row called “Miles” on the leaderboard, so you just need to create a new folder, call it “Miles” and then parent it to the leaderstats.

local m = Instance.new("Folder")
m.Name = "Miles"
m.Parent = leaderstats

Edit: It should be a IntValue or a StringValue, not a Folder.

local m = Instance.new("IntValue")
m.Name = "Miles"
m.Parent = leaderstats
2 Likes

Should be an IntValue so they can assign a value to it.

@ReaperNook A variable cannot have two values. If I assign x to 1, and then re-assign x to 2, next time I reference x it will only give me 2

You should have currencyName and milesName, and have separate logic for both in regards to saving, loading, and creating leaderstats for them.

2 Likes

So I need a different script or can I put in the same script?

Just to expand on your point:
The Developer Hub has an article about leaderboards.
Also, you should probably not have 2 variables called the same thing:

local currency = Money
local currency2 = milage

The above is probably A better option in Any situation involving variables.

If you want you could just put this script in the “SeverScript Service”

local function onPlayerJoin(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
 
	
	local money = Instance.new("IntValue")
	money.Name = "Money"
	Money.Value = 0
	Money.Parent = leaderstats

local miles = Instance.new("IntValue")
	miles.Name = "Miles"
	miles.Value = 0
	miles.Parent = leaderstats
end
 
game.Players.PlayerAdded:Connect(onPlayerJoin)

Hope this helped!
:grin:

1 Like

You can put them in the same script as seen above.
Edit: You can also connect the values to the same datastore or different ones(both of which can be done in the same script.)

3 Likes

It works thank you guys so much… This is literally the first script I didn’t ask where line do I put the script on and where do I put it. Thanks for leading me on right path!!

2 Likes