Probably because your datasaving code is taking too long.
Try putting the characterAdded event at the top.
Like this:
local Players = game:GetService("Players");
function Add(Player)
Player.CharacterAdded:Connect(function(Char)
print(Char.Name)
end)
--Other code
end
Players.PlayerAdded:Connect(Add);
sometimes the character gets created before the script has a chance to do the characteradded function. I would suggest making a function for your character added & humanoid died functions and call them twice something like this
local function HumanoidDied(char)
-- Humanoid Died Stuff
end
local function CharacterAdded(char)
-- Character Added Stuff
HumanoidDied(char)
end
game.Players.PlayerAdded:Connect(function(plr)
local char = plr.Character or plr.CharacterAdded:Wait()
CharacterAdded(char)
plr.CharacterAdded:Connect(CharacterAdded)
end)
local Players = game:GetService("Players")
local function onCharacterAdded(character: Model)
...
end
Players.PlayerAdded:Connect(function(player)
...
if player.Character then
onCharacterAdded(player.Character)
end
player.CharacterAdded:Connect(onCharacterAdded)
end)
Take one of the scripts that were posted here (I would recommend PhoenixCausesOof’s script)
And then just put a Humanoid.Died event in the CharacterAdded function
CharacterAdded has always had an issue where many times it won’t fire for whatever reason, unless you load the character manually. This basically disables the automatic loading of the character at the start of the game and when it dies, and instead does it manually assuring the event will fire. I’ve had this issue in the past and this solution has always worked