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

DataStore Isn't Loading When I Join Game But Still Tells Me It Saves?

Asked by 4 years ago

Usually this works, it prints that it saved but still fails to save. I've been trying this for about 30 minutes and i'm still struggling to find an answer.

local dataService = game:GetService("DataStoreService"):GetDataStore("AWGIOJIOJHGHAWH")

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

    local ReflectionTime = Instance.new("NumberValue", stats)
    ReflectionTime.Name = "ReflectionTime"

    local key = plr.UserId.. "-key"

    local savedValues = dataService:GetAsync(key)

    if savedValues then
        ReflectionTime.Value = savedValues[1]
    else
        local values = {ReflectionTime.Value}
        dataService:SetAsync(key, values)
    end
end)

game.Players.PlayerRemoving:Connect(function(plr)
    print("Player Leaving")
    local ReflectionTime = plr:WaitForChild("leaderstats"):WaitForChild("ReflectionTime")

    local key = plr.UserId.. "-key"
    local values = {ReflectionTime.Value}
    dataService:SetAsync(key, values)
    print("Saved")
end)

Thanks!

0
Most of the cases, you can't use DataStore in Studio, it should use in real game. Block_manvn 395 — 4y
0
Make sure you have filtering enabled, in my experiences it glitches with it off. :/ Aeroporia 37 — 4y

Answer this question