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

Values wont save on datastore?

Asked by 4 years ago

I'm trying to make a DataStore script but, my values won't save. I'm also watching tutrials on youtube on how to code DataStores to check if some of the parts of my code are wrong but still, no luck. Is there something wrong with the code?

Server Script:

local DataStore = game:GetService("DataStoreService")
local DS = DataStore:GetDataStore("CoinsAndGems")

game.Players.PlayerAdded:Connect(function(plr)

    local leaderboard = Instance.new("Folder", plr)
    leaderboard.Name = "leaderstats"

    local money = Instance.new("IntValue", leaderboard)
    money.Name = "Money"

    local key = "user"..plr.UserId
    local savedValues = DS:GetAsync(key)

    if savedValues then
        money.Value = savedValues
    else
        local saveValues = (money.Value)
        DS:SetAsync(key, saveValues)
    end

end)

game.Players.PlayerRemoving:Connect(function(plr)

    local leaderboard = plr:WaitForChild("leaderstats")
    local money = leaderboard.Money
    local key = "user-"..plr.UserId

    DS:SetAsync(key, money.Value)

end)

2 answers

Log in to vote
0
Answered by
CjayPlyz 643 Moderation Voter
4 years ago
local DataStore = game:GetService("DataStoreService")
local DS = DataStore:GetDataStore("CoinsAndGems")

game.Players.PlayerAdded:Connect(function(plr)

    local leaderboard = Instance.new("Folder", plr)
    leaderboard.Name = "leaderstats"

    local money = Instance.new("IntValue", leaderboard)
    money.Name = "Money"

    local key = "user-"..plr.UserId
    local savedValues = DS:GetAsync(key)

    if savedValues then
        money.Value = savedValues
    else
        local saveValues = (money.Value)
        DS:SetAsync(key, saveValues)
    end

end)

game.Players.PlayerRemoving:Connect(function(plr)

    local leaderboard = plr:WaitForChild("leaderstats")
    local money = leaderboard.Money
    local key = "user-"..plr.UserId

    DS:SetAsync(key, money.Value)

end)

You misspelled the key on line 12

Ad
Log in to vote
0
Answered by
CjayPlyz 643 Moderation Voter
4 years ago
local DataStore = game:GetService("DataStoreService")
local DS = DataStore:GetDataStore("CoinsAndGems")

game.Players.PlayerAdded:Connect(function(plr)

    local leaderboard = Instance.new("Folder", plr)
    leaderboard.Name = "leaderstats"

    local money = Instance.new("IntValue", leaderboard)
    money.Name = "Money"

    local key = "user-"..plr.UserId
    local savedValues = DS:GetAsync(key)

    if savedValues then
        money.Value = savedValues
    else
        local saveValues = (money.Value)
        DS:SetAsync(key, saveValues)
    end

end)

game.Players.PlayerRemoving:Connect(function(plr)

    local leaderboard = plr:WaitForChild("leaderstats")
    local money = leaderboard.Money
    local key = "user-"..plr.UserId

    DS:SetAsync(key, money.Value)

end)

You misspelled the key on line 12

Answer this question