Help With Character Added

So I currently have a stat/attribute point system, and you can increase your max health and health etc. However whenever the player first joins the game, their health is the default,100. However if they reset their health is changed to what its supposed to be. However sometimes, it actually works. Any fixes? Also no output errors and its in a server script.

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		local attr = player:WaitForChild("Attributes")

		local breathing = attr.Breathing

		local health = attr.Health

		local speed = attr.Speed
		
		local hpPerPoint = 10
		
		local newhealth = 100 + health.Value * hpPerPoint

		character:WaitForChild("Humanoid").MaxHealth = newhealth
		character:WaitForChild("Humanoid").Health = newhealth
		print(player.Character.Humanoid.MaxHealth)
	end)
end)

I’m not sure if it has something to do with default roblox loading character thingy. I suggest you added a single wait() to the CharacterAdded function so that the character gets to load properly as stated here.

When the Character is added, we wait for RunService.Stepped to fire once (using the wait function of events). This is so the accessory removal logic runs one frame after the character spawns.

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		
		wait()
		
		local attr = player:WaitForChild("Attributes")

		local breathing = attr.Breathing

		local health = attr.Health

		local speed = attr.Speed

		local hpPerPoint = 10

		local newhealth = 100 + health.Value * hpPerPoint

		character:WaitForChild("Humanoid").MaxHealth = newhealth
		character:WaitForChild("Humanoid").Health = newhealth
		print(player.Character.Humanoid.MaxHealth)
	end)
end)