So I used this guide to learn datastore. I keep getting 13:41:16.994 - ServerScriptService.Stat_Saver:24: attempt to index local 'data' (a nil value)
local DSS = game:GetService("DataStoreService")
local dataStore = DSS:GetDataStore("Stats", "Players")
function makeDataKey(player)
local ret = "uid_"..player.userId
return ret
end
function makeDataTable(player)
local statsTable = {
AttVal = player:findFirstChild("Data").AttVal.Value
}
return statsTable()
end
function savePlayerData(player)
local key = makeDataKey(player)
local data = makeDataTable(player)
dataStore:SetAsync(key,data)
end
function giveDataToPlayer(player, data)
--The error is here
player.Data.AttVal.Value = data.AttVal
end
function loadPlayerData(player)
local key = makeDataKey(player)
local data = dataStore:GetAsync(key)
giveDataToPlayer(player, data)
end
game.Players.PlayerAdded:connect(function(player)
wait(5)
loadPlayerData(player)
print("Loaded Data")
player.Data.Level.Changed:connect(function()
savePlayerData(player)
print("Data saved")
end)
end)
game.Players.PlayerRemoving:connect(savePlayerData)

1 comment
Well thanks that stops me from getting a nil value but it doesn't even save data xd. Going to find a new tutorial and try again.