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

How do I add multiple leaderstats?

Asked by 6 years ago
Edited 6 years ago

So I am trying to make multiple Leaderstats, but there is one problem, whenever I join the game chooses one of the leaderstats and makes the other one nil? what is the problem?

here's the script for the first leaderstat:

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

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

Script for the 2nd leaderstat:

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

             local Fishies = Instance.new("IntValue", stats)
              Fishies.Name = "FishCaught"
              Fishies.Value = 0
                end)

1 answer

Log in to vote
0
Answered by
chomboghai 2044 Moderation Voter Community Moderator
6 years ago

You are creating two instances of leaderstats. You can only have one instance, then append all of your individual stats to that instance.

As a side note, don't use the Instance.new("IntValue", stats) because it can give a huge performance hit in the long run. You should do Instance.new("IntValue"), then set all properties of that instance, then parent it afterwards using stat.Parent = stats

Ad

Answer this question