I’ve been trying to store hidden data of Player in the Player just like leaderstats but in a separate folder but it keeps giving me a warning stating it failed to Load data and Augment 2 missing or nil. I’m at a complete loss on what I’m doing wrong.
local DataStoreService = game:GetService("DataStoreService")
local MyDataStore = DataStoreService:GetDataStore("MyDataStore")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Coin = Instance.new("IntValue")
Coin.Name = "Coin"
Coin.Parent = leaderstats
local Diamonds = Instance.new("IntValue")
Diamonds.Name = "Diamonds"
Diamonds.Parent = leaderstats
local Collectibles = Instance.new("IntValue")
Collectibles.Name = "Collectibles"
Collectibles.Parent = leaderstats
-------Appearance------
local Appearance = Instance.new("Folder")
Appearance.Name = "Appearance"
Appearance.Parent = player
local Color = Instance.new("IntValue")
Color.Name = "Color"
Color.Value = 0
Color.Parent = Appearance
--Data Being Found-
local dataCoin
local dataDiamond
local datacollect
local colorstore
local success, errormessage = pcall(function()
dataCoin = MyDataStore:GetAsync(player.UserId.."-Coin")
dataDiamond = MyDataStore:GetAsync(player.UserId.."-Diamonds")
datacollect = MyDataStore:GetAsync(player.UserId.."-Collectibles")
colorstore = MyDataStore:SetAsync(player.UserId.."-Color")
end)
if success then
Coin.Value = dataCoin
Diamonds.Value = dataDiamond
Collectibles.Value = datacollect
Color.Value = colorstore
else
print(player.Name.."'s Data Error Loading")
warn(errormessage)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local success, errormessage = pcall(function()
MyDataStore:SetAsync(player.UserId.."-Color",player.Appearance.Color.Value)
MyDataStore:SetAsync(player.UserId.."-Coin",player.leaderstats.Pixels.Value)
MyDataStore:SetAsync(player.UserId.."-Diamonds",player.leaderstats.Glim.Value)
MyDataStore:SetAsync(player.UserId.."-Collectibles",player.leaderstats.Collectibles.Value)
end)
if success then
print(player.Name.."'s Data Was Saved Successfully!")
else
print("There was an error in saving player data")
warn(errormessage)
end
end)