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

DataStore not loading/saving leaderstats??

Asked by
Kulh 125
6 years ago
Edited 6 years ago

Here's the code to load the stats:

local DataStore = game:GetService("DataStoreService"):GetDataStore("SurvivalsStorage")

game.Players.PlayerAdded:connect(function(player)

local stats = Instance.new("IntValue", player)
stats.Name = "leaderstats"
local Survivals = Instance.new("IntValue" , stats)
Survivals.Name = "Survivals"

local Key = "user-"..player.userId

local SaveWins = DataStore:GetAsync(Key)

if SaveWins then
    --save format: 
    Survivals.Value = SaveWins[1]
else
    local ValuesToSave = {Survivals.Value}
    DataStore:SetAsync(Key, ValuesToSave)
end

end)

game.Workspace.ChildAdded:connect(Findthenoob)

Here's the code that saves the stats:

local DataStore = game:GetService("DataStoreService"):GetDataStore("SurvivalsStorage")

game.Players.PlayerRemoving:connect(function(player)

    local Key = "user-"..player.userId

    local ValuesToSave = {player.leaderstats.Survivals.Value}
    DataStore:SetAsync(Key, ValuesToSave)

end)

Both are Server scripts in workspace

NOTE: I HAVE FILTERING ENABLED

0
Anyway i could fix this? Kulh 125 — 6y
0
??? Kulh 125 — 6y

Answer this question