The next nil value comes from here:
game.Players.PlayerRemoving:Connect(function(plr)
local Data = {
CatFood = plr.leaderstats.CatFood.Value,
XP = plr.leaderstats.XP.Value,
Coconuts = plr.leaderstats.Coconuts.Value,
Seashells = plr.leaderstats.Seashells.Value,
}
local PlayerID = "Player_"..plr.UserId
local success, err = pcall(function()
DataStore:SetAsync(PlayerID,Data)
end)
end)
DataStore:SetAsync(PlayerID,Data)
The script doesn’t know what DataStore is since it’s mentioned in the playeradded function