Hello, the issue is simple, i tried doing a datastore script using table with character values, but using print, it always return the data as nil
I already tried: Using attributes, waitforchild in both character and values, using folders and without folders, using instance.new().
local datasservice = game:GetService("DataStoreService")
local datastore1 = datasservice:GetDataStore("datastore1")
--
game.Players.PlayerRemoving:Connect(function(player)
local playerkey = "player:".. player.UserId
local char = player.Character or player.CharacterAdded:Wait()
local data = {
atk = char.stats.atk;
def = char.stats.def;
dex = char.stats.dex;
mana = char.stats.mana;
manamax = char.stats.manamax;
vit = char.stats.vit;
wis = char.stats.wis;
}
--
local success, errormessage = pcall(function()
datastore1:SetAsync(playerkey, data)
end)
if success then
print(player.Name.. "'s data successfully saved")
else
warn(errormessage)
end
end)
--
game.Players.PlayerAdded:Connect(function(player)
local playerkey = "player:".. player.UserId
local char = player.Character or player.CharacterAdded:Wait()
--
local success, errormessage, data = pcall(function()
return datastore1:GetAsync(playerkey)
end)
print('typeofchar:'.. typeof(char))
print(data)
if success then
char.stats.atk = data.atk
char.stats.def = data.def
char.stats.dex = data.dex
char.stats.mana = data.mana
char.stats.manamax = data.manamax
char.stats.vit = data.vit
char.stats.wis = data.wis
char.Humanoid.Health = data.health
char.Humanoid.MaxHealth = data.healthmax
print("data successfully loaded")
else
warn(errormessage)
end
end)
Here is the error:
there is the folder:
and here is nil: (print(data))