So I’m trying to use the “getOrderedDataStore()” on my leaderstats, but for some reason it can’t because my leaderstats aren’t comprehendible for that. so can someone show me or change my leaderstats so they are able to be used in the ordered data store?
local DataStore = game:GetService("DataStoreService")
local myDataStore = DataStore:GetDataStore("myDataStore")
game.Players.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = plr
local luck = Instance.new("NumberValue")
luck.Name = "Luck"
luck.Parent = leaderstats
luck.Value = 0
local data
local success, errormessage = pcall(function()
data = myDataStore:GetAsync(plr.UserId.."-Luck")
end)
if success then
luck.Value = data
else
print("There was an error while giving Player Data.")
warn(errormessage)
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
local success, errormessage = pcall(function()
myDataStore:SetAsync(plr.UserId.."-Luck", plr.leaderstats.Luck.Value)
end)
if success then
print("Player Data successfully saved!")
else
print("There was an error while saving Player Data.")
warn(errormessage)
end
end)