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

Data Store doesn't Save/Load?

Asked by
lomo0987 250 Moderation Voter
9 years ago

I have done some reading for the Data Store and I came up with this script...

local Store = game:GetService("DataStoreService"):GetDataStore("XP/LEVEL")

game.Players.PlayerAdded:connect(function (player)
    local playername = player.Name
    local stats = Instance.new("IntValue")
    stats.Name = "leaderstats"
    stats.Parent = player

    local xp = Instance.new("IntValue")
    local xpStats = Store:GetAsync(playername.."XP")
    xp.Name = "XP"
    xp.Value = xpStats or 0
    xp.Parent = stats

    local Level = Instance.new("IntValue")
    local xpLevel = Store:GetAsync(playername.."LEVEL")
    Level.Name = "Level"
    Level.Value = xpLevel or 1
    Level.Parent = stats
end)

game.Players.PlayerRemoving:connect(function (player)
    local playername = player.Name
    local XP = player.leaderstats:FindFirstChild("XP")
    Store:SetAsync(playername.."XP",XP.Value)

    local LEVEL = player.leaderstats:FindFirstChild("Level")
    Store:SetAsync(playername.."LEVEL", LEVEL.Value)
end)

It loads fine, there is no errors on the output.. But it doesn't want to save or load the value's. Did I do the "Store:GetAsync" and the Store:SetAsync" incorrectly?

Answer this question