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

My leaderboard not working?

Asked by 8 years ago

I am using roblox wiki and hve made this so far, it is not working though? Help please XD I am trying so hard not to give up like people said. I don't want to :D I must keep going

--Jo3's First LeaderBoard & Improvements to come.

game.Players.PlayerAdded:connect(function(player) local leaderstats = Instance.new("Model") leaderstats.Name = "Jo3thebombsStats" leaderstats.Parent = player local money = Instance.new("IntValue") money.Name = "Money" money.Value = 0 money.Parent = leaderstats local fish = Instance.new("IntValue") fish.name = "Fish" fish.Value = 0 fish.Parent = leaderstats end)

0
Please lua block your script xAtom_ik 574 — 8y

1 answer

Log in to vote
3
Answered by 8 years ago

Formatting:

Firstly, let's put your code into a code block using the little Lua button when making your post.

--Jo3's First LeaderBoard & Improvements to come.

game.Players.PlayerAdded:connect(function(player) local leaderstats = Instance.new("Model") leaderstats.Name = "Jo3thebombsStats" leaderstats.Parent = player local money = Instance.new("IntValue") money.Name = "Money" money.Value = 0 money.Parent = leaderstats local fish = Instance.new("IntValue") fish.name = "Fish" fish.Value = 0 fish.Parent = leaderstats end)

Much better, now we can see the syntax you're using! But, the code is messy and unreadable. Let's add line breaks to it and make some whitespace to make it more visible.

--Jo3's First LeaderBoard & Improvements to come.

game.Players.PlayerAdded:connect(function(player)
    local leaderstats = Instance.new("Model") 
    leaderstats.Name = "Jo3thebombsStats" 
    leaderstats.Parent = player 
    local money = Instance.new("IntValue") 
    money.Name = "Money" 
    money.Value = 0 
    money.Parent = leaderstats 
    local fish = Instance.new("IntValue") 
    fish.name = "Fish" 
    fish.Value = 0 
    fish.Parent = leaderstats 
end)

Now this is more like it! You, I and many others can now see that the code is formatted correctly and now we can begin to find out what the problem is.


The problem:

So, the problem is that you're not naming your leaderstats model "leaderstats". ROBLOX requires you to make an object with the name of leaderstats to add items to the leaderboard. So, we can now change this:

--Jo3's First LeaderBoard & Improvements to come.

game.Players.PlayerAdded:connect(function(player)
    local leaderstats = Instance.new("Model") 
    leaderstats.Name = "leaderstats" 
    leaderstats.Parent = player 
    local money = Instance.new("IntValue") 
    money.Name = "Money" 
    money.Value = 0 
    money.Parent = leaderstats 
    local fish = Instance.new("IntValue") 
    fish.name = "Fish" 
    fish.Value = 0 
    fish.Parent = leaderstats 
end)

Improvements to the code itself:

Now that should work. But, we can make this code more efficient. There is a second argument to the Instance.new method which sets the parent for you.

This gets rid of one less line from each time you make a new instance and shortens your code, which is very helpful when people are trying to read your code as they have less to read.


Final code:

--Jo3's First LeaderBoard & Improvements to come.

game.Players.PlayerAdded:connect(function(player)
    local leaderstats = Instance.new("Model",player) 
    leaderstats.Name = "leaderstats" 
    local money = Instance.new("IntValue",leaderstats) 
    money.Name = "Money" 
    money.Value = 0 
    local fish = Instance.new("IntValue",leaderstats) 
    fish.name = "Fish" 
    fish.Value = 0 
end)

I hope my answer helped you. If it did, be sure to accept it.

0
Ahh i just fixed it right before you send this haha thx jo3thebomb 12 — 8y
0
No problem. Spongocardo 1991 — 8y
Ad

Answer this question