I am trying to save player.Codes.Roy.Value, Codes is a folder I put into player, what could the problem be, why is this not saving and/or loading?
On Player Added
local DataStore = game:GetService("DataStoreService"):GetDataStore("Store")
game.Players.PlayerAdded:connect(function(player)
local key = "player-"..player.userId
local savedValues = DataStore:GetAsync(key)
if savedValues then
player.Codes.Roy.Value = savedValues[1]
else
local valuesToSave = {player.Codes.Roy.Value}
DataStore:SetAsync(key, valuesToSave)
print("Data Loaded")
end
end)
On Player Leaving
local DataStore = game:GetService("DataStoreService"):GetDataStore("Store")
game.Players.PlayerRemoving:connect(function(player)
local key = "player-"..player.userId
local valuesToSave = {player.Codes.Roy.Value}
DataStore:SetAsync(key, valuesToSave)
print("Data Saved")
end)
