Hi, any idea why it’s warning “value of type nil cannot be converted to a number” for line: player.leaderstats.Rebirths.Value = data[1]
Full code below
local DataStoreService = game:GetService("DataStoreService")
local LeaderboardDS = DataStoreService:GetDataStore("Dev4")
game.Players.PlayerRemoving:Connect(function(player) -- Save data when leving
local SaveStats = {
print(player),
player.leaderstats.Cash.Value,
player.leaderstats.Rebirths.Value,
}
local success, fail = pcall(function()
LeaderboardDS:SetAsync(player.UserId, SaveStats)
end)
if success then
print("Data saved")
else
print("Data not saved")
warn(fail)
end
end)
game.Players.PlayerAdded:Connect(function(player) -- Load data function
local data
local success, fail = pcall(function()
data = LeaderboardDS:GetAsync(player.UserId)
end)
if success and data then
player.leaderstats.Cash.Value = data[2]
player.leaderstats.Rebirths.Value = data[1]
else
print("No data")
player.leaderstats.Cash.Value = 0
player.leaderstats.Rebirths.Value = 0
end
end)