These leaderstats are good but there are better ones that use NumberValues as leaderstats, and it's so much easier to add more of them and it goes up to even infinite amounts of leaderstat names! Simply put this script inside of ServerScriptService and put NumberValues inside of it. Make sure the values are named after the leaderstats u want in ur game. Only one of the leaderstats will work inside of Studio, normally they all work, so u should probably make a testing place if u dont have one already. Hope this helped!
01 | game.Players.PlayerAdded:connect( function (player) |
02 | local DataStore = game:GetService( "DataStoreService" ) |
04 | local leader = Instance.new( "Folder" ,player) |
05 | leader.Name = "leaderstats" |
07 | for i,v in pairs (script:GetChildren()) do |
08 | local d = DataStore:GetDataStore(v.Name) |
09 | local x = Instance.new( "NumberValue" ,leader) |
11 | x.Value = d:GetAsync(player.UserId) or v.Value |
18 | game.Players.PlayerRemoving:Connect( function (player) |
19 | for i,v in pairs (script:GetChildren()) do |
21 | local DataStore = game:GetService( "DataStoreService" ) |
22 | local d = DataStore:GetDataStore(v.Name) |
23 | d:SetAsync(player.UserId, player.leaderstats [ v.Name ] .Value) |