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

I'm having trouble with a leaderboard and datastore variables, can someone help?

Asked by 6 years ago

Title: I'm having trouble with a datastore and leaderboard, I'm a beginner at datastore, can some please help?

ServerScriptServiec.leaderstats:18: attempt to index local 'saved' (a nil value)

local datastore = game:GetService('DataStoreService'):GetDataStore("Friends")

game.Players.PlayerAdded:connect(function(player)
        local leaderstats = Instance.new("IntValue", player)
        local friends = Instance.new("IntValue", leaderstats)   

        leaderstats.Name = 'leaderstats'
        friends.Name = "Friends"

        local uniquekey = "friends-"..player.userId
        local pointsvalue = player.leaderstats.Friends.Value
        local saved = datastore:SetAsync(uniquekey, pointsvalue)        


        if saved then
            pointsvalue = saved[1] 
            else
            saved:GetAsync(uniquekey, pointsvalue)
        end     




end)

game.Players.PlayerRemoving:connect(function(player)
    local pointsvalue = player.leaderstats.Friends.Value
    local uniquekey = "friends-"..player.userId 

    datastore:SetAsync(uniquekey, pointsvalue)
end)
0
You save and load data through the data store. You are trying to save it through the value returned from a data store. User#5423 17 — 6y
0
Could you explain that? I'm not exactly sure what you mean by that. StarMarine614Classic 14 — 6y

Answer this question