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

How do I add another stat datastore save to my stats script?

Asked by 4 years ago

Hello, So I'm making a game and I was wondering how can I add so my kills stat would save. I already added it so I just need the save thingy. The problem is that a guy on here gave me this script and I don't really understand it that much.

My code:

01local DataStoreService = game:GetService("DataStoreService")
02local CashDS = DataStoreService:GetDataStore("Cash")
03local RS = game:GetService("RunService")
04 
05game.Players.PlayerAdded:Connect(function(plr)
06    local Cash = Instance.new("IntValue")
07    Cash.Name = "Cash"
08    Cash.Parent = plr
09    Cash.Value = 0
10 
11    local Kills = Instance.new("IntValue")
12    Kills.Name = "Kills"
13    Kills.Parent = plr
14    Kills.Value = 0
15 
View all 77 lines...

1 answer

Log in to vote
1
Answered by
Gogulsky 129
4 years ago

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!

01game.Players.PlayerAdded:connect(function(player)
02local DataStore = game:GetService("DataStoreService")
03 
04     local leader = Instance.new("Folder",player)
05leader.Name = "leaderstats"
06 
07for i,v in pairs(script:GetChildren()) do
08local d = DataStore:GetDataStore(v.Name)
09local x = Instance.new("NumberValue",leader)
10x.Name = v.Name
11x.Value = d:GetAsync(player.UserId) or v.Value
12 
13 
14 
15end
View all 26 lines...
Ad

Answer this question