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

DataStore not saving? (Filtering Enabled)

Asked by 6 years ago
01local DataStore = game:GetService("DataStoreService")
02local ds = DataStore:GetDataStore("hellomynameijks45346345")
03 
04game.Players.PlayerAdded:connect(function(plr)
05 
06a = Instance.new("Folder", plr)
07a.Name = "leaderstats"
08    Vals = ds:GetAsync(plr.UserId)
09    print(Vals)
10    if Vals then
11        for i, v in pairs(game.ReplicatedStorage.Values:GetChildren()) do
12            print(v)
13            Found = game.ReplicatedStorage.Values:FindFirstChild(v.Name)
14            print("yes")
15            if Found then
View all 32 lines...

I can't find the problem, when I leave the game, it prints the variable that was in my leaderstats. But when I then enter the game, the GetAsync return nil to Vals. Anyone know why?

1 answer

Log in to vote
1
Answered by
Amiaa16 3227 Moderation Voter Community Moderator
6 years ago

Perhaps the script doesn't have enough time to save the values, because the game shuts down before it manages to?

Try keeping the server alive till the data is saved by using game:BindToClose().

01local plrs = {}
02local allSaved = false
03 
04local function GetCount(t)
05    local i = 0
06    for _,v in pairs(t) do
07        i = i + 1
08    end
09    return i
10end
11 
12game.Players.PlayerAdded:Connect(function(plr)
13    plrs[plr.Name] = true
14end)
15 
View all 30 lines...
Ad

Answer this question